Question:
I’ve created a few Lambda functions that get triggered by API-Gateway events.
Now I want to enable CORS for these endpoints, but it doesn’t seem to work. In the last few versions of AWS SAM the CORS functionality was added or updated, but I still can’t get it to work.
This is what I tried:
1 2 3 4 |
Gobals: Api: Cors: "'*'" |
Answer:
You can also specify these in your lambda handlers (Python example):
1 2 3 4 5 6 7 8 9 |
return { 'statusCode': status_code, 'headers': { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }, 'body': status_message if status_code == 200 else 'Failure' } |