- Newest
- Most votes
- Most comments
Hello.
Although you cannot see the Terraform code due to AccessDenied, I think you can troubleshoot general CORS errors when using API Gateway and Lambda by following the steps in the following document.
After enabling CORS in API Gateway, deploy the API.
In addition to configuring API Gateway, make sure that the code is written so that the Lambda response returns "Access-Control-Allow-Origin" or similar.
https://repost.aws/knowledge-center/api-gateway-cors-errors
https://www.cloudtechsimplified.com/cors-error-api-gateway-aws-lambda/
Thank you for answering. My Lambda code already includes the headers in the return:
return { 'statusCode': 200, 'headers': { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'https://www.umamicloudchallenge.org', 'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token', 'Access-Control-Allow-Methods': 'POST,OPTIONS' },
The full code:
import boto3 # type: ignore import json table_name = "count-table" dynamo = boto3.resource('dynamodb').Table(table_name) def read(payload): return dynamo.get_item(Key=payload['Key']) operations = {'read': read} def lambda_handler(event, context): try: # Check if the request is coming from API Gateway if 'body' in event and isinstance(event['body'], str): # Parse the body from API Gateway body = json.loads(event['body']) operation = body['operation'] payload = body['payload'] else: # Direct Lambda invocation operation = event['operation'] payload = event['payload'] if operation in operations: result = operations[operation](payload) return { 'statusCode': 200, 'headers': { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'https://www.umamicloudchallenge.org', 'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token', 'Access-Control-Allow-Methods': 'POST,OPTIONS' }, 'body': json.dumps(result, default=str) } else: return { 'statusCode': 400, 'headers': { 'Content-Type': 'application/json', 'Access-Contro
If you are using Lambda in Proxy mode on APi Gateway , you will need to include the CORS policy in the response from the Lambda function
Relevant content
- AWS OFFICIALUpdated 6 months ago

Cant read your TF files. They are not public!
It is public now