I have API Gateway endpoints which execute lambda functions. I want to protect my api endpoints with using aws_iam as authorizer. I have a user pool with federated identities set up for this. However after implementing it into the cloudformation template I get an cors error calling it from my angular app with an authenticated user:
Access to XMLHttpRequest at 'api endpoint url' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
here is the code of my cf template:
create:
handler: functions/api-create.create
events:
- http:
path: get/create
method: get
authorizer: aws_iam
cors: true
my lambda function looks like this:
export const create = async (event, context) => {
console.log('Create: ', event)
console.log('Context: ', context)
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: JSON.stringify({
product: "hallo"
}),
};
return response;
};
Without authorizer: aws_iam
everything works fine and I get the expected response. Does anyone know what I could be missing here.