AWS Lambda and CORS preflight response

Are you struggling with a frontend application that wants to use a backend AWS Lambda API ? Do you have the next CORS problem: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response The solution is simple: implement HTTP OPTIONS method respond with the next access control headers : Access-Control-Allow-Origin, Access-Control-Allow-Headers, Access-Control-Allow-Methods For example in python you can do something like this: def return_200(): return { 'statusCode': 200, 'headers': { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET,HEAD,OPTIONS,POST,PUT', 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization', 'Content-Type': 'application/json' }, 'body': json....

December 9, 2024 · 1 min · Alex Popescu

Deploying docker image to AWS Fargate in GitHub

Let’s deploy a docker image to AWS ECR and further to AWS Fargate. If you don’t have docker installed, now is the time to do it. GitHub Action YML: Create a workflow named main-aws.yml, for example as: name: Deploy to Amazon ECS on: workflow_dispatch: env: AWS_REGION: eu-central-1 # set this to your preferred AWS region, e.g. us-west-1 ECS_SERVICE: test-svc # set this to your Amazon ECS service name ECS_CLUSTER: test-fargate-dev # set this to your Amazon ECS cluster name ECS_TASK_DEFINITION: ....

December 9, 2024 · 5 min · Alex Popescu