Create DELETE API

  1. Open template.yaml file in fcj-book-store folder
  2. Add the following script at the end of the file that create the DELETE method
          /books/{id}:
            delete:
              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/${BookDelete.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

CreateDeleteAPI

  • Add the following script at the end of the BookDelete function
      Events:
        DeleteBook:
          Type: Api
          Properties:
            Path: /books/{id}
            Method: delete
            RestApiId:
              Ref: BookApi

CreateDeleteAPI

  1. Run the following command to deploy SAM
sam build
sam deploy --guided

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

CreateDeleteAPI

  1. Open book_delete function console
  • Click API Gateway

CreateDeleteAPI

  1. Show API Gateway being interacted with this function
  • Click this API Gateway

CreateDeleteAPI

  1. Display the resources and DELETE method

CreateDeleteAPI

  1. Click Stages on the left menu
  • Click staging
  • Click DELTE
  • Record the InvokeURL of DELETE method

CreateDeleteAPI

  1. Add the following script at the end of the template.yaml file to API can support Binary Media Types files
      BinaryMediaTypes: 
        - multipart~1form-data
  1. Run the following command to deploy SAM
sam build
sam deploy --guided

CreateDeleteAPI

  1. Back to API console
  • Select Settings on the left menu
  • Scroll down, check if multipart/form-data has been added under Binary Meida Types

CreateDeleteAPI