How to do it...

Let's create an API with CORS enabled from scratch. Steps 1 to 4 are the same as we have seen in Chapter 2, Building Serverless REST APIs with API Gateway:

  1. Create an API:
aws apigateway create-rest-api \    --name 'API WITH CORS' \    --region us-east-1 \    --profile admin
I will not display the region and profile parameters for further commands. You may either add them manually to every command or configure them as the defaults with the AWS CLI configuration.
  1. Get the ID of the root resource path \:
aws apigateway get-resources \    --rest-api-id xenqybowjg
  1. Create a resource greeting under the root path:
aws apigateway create-resource  \    --rest-api-id xenqybowjg \    --parent-id p8yd8xde55 \    --path-part greeting
  1. Create a subresource ...

Get Serverless Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.