Create DELETE 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 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
    

    CreatePostAPI

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

    CreatePostAPI

  3. Run the following command to deploy SAM

    sam build
    sam deploy --guided
    

    CreatePostAPI

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

  4. Open book_delete function console

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

    • Click this API Gateway
  6. Display the resources and DELETE method CreatePostAPI

  7. Click Stages on the left menu

    • Click staging
    • Click DELTE
    • Record the InvokeURL of DELETE method CreatePostAPI
  8. Add the following script at the end of the template.yaml file to API can support Binary Media Types files

          BinaryMediaTypes: 
            - multipart~1form-data
    
  9. Run the following command to deploy SAM

    sam build
    sam deploy --guided
    

    CreatePostAPI

  10. Back to API console

    • Select Settings on the left menu
    • Scroll down, check if multipart/form-data has been added under Binary Meida Types CreatePostAPI