I have created a lambda function from cloudformation template code, added authorization of cognito user and it works fine in postman, but when calling it from localhost:3000 it is giving cors error.
Have attached SS of calling api and cloudformation template code.
Would appreciate a help.
Thanks in Advance..!
- Sample code of cloudformation template:
AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Application.
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Cors:
AllowMethods: "'GET,POST,OPTIONS'"
AllowHeaders: "'Content-Type','X-Amz-Date','Authorization','X-Api-Key','X-Amz-Security-Token'"
AllowOrigin: "'http://localhost:3000'"
ItemFunction:
Type: AWS::Serverless::Function
Name: ReadAllItem
Properties:
CodeUri: ''
Handler: AWSServerless2::AWSServerless2.MyCRUDFunction::ReadAll
Runtime: dotnet6
Timeout: 30
Events:
GetItem: # Corrected event ID to match the event type
Type: Api
Properties:
Path: /items
Method: get
RestApiId: !Ref MyApi # Reference the API resource
Outputs: {}
Thanks have studies above links and works fine without authorizer, but when i configure it for authorizer getting cors error, can you look at this question https://repost.aws/questions/QUmYWTg_ixRtON2N34eADAzA/getting-cors-error-when-calling-lamda-function-from-frontend