Create POST API

  1. Open template.yaml file in fcj-book-shop folder
  2. Add the following script at the end of the file that create the POST method
                post:
                  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/${BookCreate.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
    
    CreatePostAPI
  • Add the following script at the end of the BookCreate function
          Events:
            CreateBook:
              Type: Api
              Properties:
                Path: /books/
                Method: post
                RestApiId:
                  Ref: BookApi
    
    CreatePostAPI
  1. Run the following command to deploy SAM

    sam build
    sam deploy --guided
    

    CreatePostAPI

    Enter “y” if asked “BookCreate may not have authorization defined, Is this okay? [y/N]:”

  2. Open book_create function console

    • Click API Gateway CreatePostAPI
  3. Show API Gateway being interacted with this function

    • Click this API Gateway CreatePostAPI
  4. Display the resources and POST method CreatePostAPI

  5. Click Stages on the left menu

    • Click staging
    • Click POST
    • Record InvokeURL of POST method CreatePostAPI