TECHIES WORLD

For Techs.... Techniques.... Technologies....

AWSBashLinux

How to configure Access-Control-Allow-Origin header as * for AWS API Gateway using awscli

The CORS headers can be configured for AWS API Gateway via AWS console or using the awscli.

This article explains the cli command to configure Access-Control-Allow-Origin header as * for AWS API Gateway.

#aws apigateway put-integration-response --rest-api-id API --resource-id RESOURCE --http-method GET --status-code 200 --selection-pattern 200 --response-parameters '{"method.reponse.header.Access-Control-Allow-Origin": "'"'"'*'"'"'"}'

Here we need to replace API with the id of the apigateway and RESOURCE with the id of corresponding resource.

Please note that the header value should be put exactly like "'"'"'*'"'"'". Otherwise it will lead to the following error during execution.

PutIntegrationResponse operation: Invalid mapping expression specified

That's all….