API Gateway CORS Configuration with Amplify Previews

0

Hey

How can I add any Amplify Preview URL to the CORS Configuration in the API Gateway since we can't use wildcard operators?

1 Answer
0

Just add amplify preview url in the API Gateway resource on which you need. Filling appropriate values in these fields Access-Control-Allow-Methods Access-Control-Allow-Headers Access-Control-Allow-Origin : amplify preview url

answered a year ago
  • But each preview will have a new url, that way I will have to manually add each preview

  • ok then you have to programatically handle Access-Control-Allow-Origin with api gateway response integration. Example if your api gateway intergrate with lambda function, then from lambda function you need to set which amplify preview url to be allowed. code snippet in you backend lambda response contain

    const response = { headers: { allowOrigin: amplifydomainurl } };

    and in your api gateway response integration should map it like this

    method.response.header.Access-Control-Allow-Origin: "integration.response.body.headers.allowOrigin"

    By this you can control dynamic amplify preview urls to be allowed from backend logic.

  • Getting this error: "Invalid mapping expression specified: Validation Result: warnings : [], errors : [Operations on header access-control-allow-origin are restricted]"

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions