API Gateway Method CORS ERROR - CloudFormation

0

Hello Please when try to use my API Gateway im my react i get this error but in Postman i works fine

Access to fetch at 'https://api.domainz.com/prod/sp/' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Please help How do i enable cors from my cloud formation API Gateway Method

he is my Method Code In cloudformation

spPOSTMethod:
    Type: AWS::ApiGateway::Method
    DeletionPolicy: Delete
    Properties:
      AuthorizationType: NONE #Options [CUSTOM, COGNITO_USER_POOLS, COGNITO, NONE, OAUTH2]
      HttpMethod: POST #Options [GET, POST, PUT, DELETE, PATCH, ANY]
      ResourceId: !ImportValue ExSpResources
      RestApiId: !ImportValue ExAppAPI
      Integration:
        Type: AWS_PROXY #Options [AWS_PROXY, AWS, HTTP, MOCK, AWS_PROXY_V2]
        IntegrationHttpMethod: POST #[For Lambda POST][For MOCK this property is optional]
        Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${spEventNLFn.Arn}/invocations

      RequestModels:
        application/json: !Ref spEventModel
      RequestValidatorId: !Ref spEventPOSTMethodValidator

1개 답변
1
수락된 답변

Hello.

Do you have "Access-Control-Allow-Origin" in the header when accessing API Gateway with your localhost application?
Even if CORS is configured on the API Gateway side, an error will occur if the local application does not support it.
I think the StackOverflow answers below will be helpful.
https://stackoverflow.com/questions/61238680/access-to-fetch-at-from-origin-http-localhost3000-has-been-blocked-by-cors

profile picture
전문가
답변함 8달 전
profile pictureAWS
전문가
검토됨 8달 전
profile picture
전문가
검토됨 8달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠