BookApi:
Type: AWS::Serverless::Api
Name: fcj-serverless-api
Properties:
StageName: staging
Cors: "'*'" # enable CORS for API
DefinitionBody:
openapi: 3.0.1
info:
description: "This is the APIs for book shop web app"
version: "1.0.0"
title: "API Gateway REST API to Lambda"
paths:
/books:
get:
responses:
"200":
description: 200 response
headers:
Access-Control-Allow-Origin:
type: string
x-amazon-apigateway-integration:
uri:
Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${BooksList.Arn}/invocations"
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Origin: "'*'"
passthroughBehavior: when_no_match
httpMethod: POST #always POST
type: aws_proxy
Events:
ListBook:
Type: Api
Properties:
Path: /books/
Method: get
RestApiId:
Ref: BookApi
Run the following command to deploy SAM
sam build
sam deploy
Enter “y” if asked “BooksList may not have authorization defined, Is this okay? [y/N]: "
Open Lambda console, click books_list function
Show API Gateway being interacted with function
Display resources and GET method
Click Stages on the left menu