In this step, we will add the DELETE method to allow the frontend to delete books by ID via the book_delete Lambda function.
The DELETE endpoint uses a path parameter (/books/{id}), which is already defined by the BookDeleteApiResource resource. Like the previous POST step, adding a new method requires re-creating the API deployment in two phases.
We also add a BookApiDeleteOptions resource (MOCK integration) to support browser preflight CORS requests for this endpoint.
Open the template.yaml file in the fcaj-book-shop folder.
Comment out the BookApiDeployment block and the DeploymentId line inside BookApiStage:
# BookApiDeployment:
# Type: AWS::ApiGateway::Deployment
# Properties:
# RestApiId: !Ref BookApi
# DependsOn:
# - BookApiGet
# - BookApiCreate
BookApiStage:
Type: AWS::ApiGateway::Stage
Properties:
RestApiId: !Ref BookApi
StageName: !Ref stage
# DeploymentId: !Ref BookApiDeployment

Run the commands to validate, build, and deploy:
sam validate
sam build

sam deploy
The changeset shows:
BookApiStageBookApiDeploymentEnter y to confirm.

Wait for the deployment to complete.

Add the BookApiDelete method resource. Note that ResourceId references BookDeleteApiResource (the /{id} path), not BookApiResource:
BookApiDelete:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: DELETE
RestApiId: !Ref BookApi
ResourceId: !Ref BookDeleteApiResource
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: POST # For Lambda integrations, you must set the integration method to POST
Uri: !Sub >-
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${BookDelete.Arn}/invocations
MethodResponses:
- StatusCode: "200"
ResponseParameters:
method.response.header.Access-Control-Allow-Origin: true
method.response.header.Access-Control-Allow-Methods: true
method.response.header.Access-Control-Allow-Headers: true

Add BookApiDeleteOptions (MOCK integration for CORS preflight) and BookApiDeleteInvokePermission:
BookApiDeleteOptions:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: OPTIONS
RestApiId: !Ref BookApi
ResourceId: !Ref BookDeleteApiResource
AuthorizationType: NONE
Integration:
Type: MOCK
RequestTemplates:
application/json: '{"statusCode": 200}'
IntegrationResponses:
- StatusCode: "200"
ResponseParameters:
method.response.header.Access-Control-Allow-Origin: "'*'"
method.response.header.Access-Control-Allow-Methods: "'GET,POST,OPTIONS,DELETE'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
MethodResponses:
- StatusCode: "200"
ResponseParameters:
method.response.header.Access-Control-Allow-Origin: true
method.response.header.Access-Control-Allow-Methods: true
method.response.header.Access-Control-Allow-Headers: true
BookApiDeleteInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref BookDelete
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceAccount: !Ref "AWS::AccountId"

Why add an OPTIONS method?: Browsers send a preflight OPTIONS request before a cross-origin DELETE request (CORS policy). Without this MOCK integration, the browser will block the DELETE call entirely before it even reaches your Lambda. The BookApiDeleteOptions provides a static response that grants the browser permission to proceed.
Uncomment the BookApiDeployment block and DeploymentId. Update DependsOn to include all three methods — BookApiGet, BookApiCreate, and BookApiDelete:
BookApiDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId: !Ref BookApi
DependsOn:
- BookApiGet
- BookApiCreate
- BookApiDelete
BookApiStage:
Type: AWS::ApiGateway::Stage
Properties:
RestApiId: !Ref BookApi
StageName: !Ref stage
DeploymentId: !Ref BookApiDeployment

Run the commands again to build and deploy:
sam validate
sam build

sam deploy
The changeset shows new resources being added:
BookApiDelete (AWS::ApiGateway::Method)BookApiDeleteOptions (AWS::ApiGateway::Method)BookApiDeployment (AWS::ApiGateway::Deployment)BookApiDeleteInvokePermission (AWS::Lambda::Permission)BookApiStage (AWS::ApiGateway::Stage)Enter y to confirm.

Wait for the deployment to complete. You should see Successfully created/updated stack - fcaj-book-shop in ap-southeast-1.

Open the AWS API Gateway console. Click on the fcaj-serverless-api REST API.

At the fcaj-serverless-api page:
/books → /{id} → select DELETE.
Click Stages in the left menu.
Example:
https://1bupjnr42d.execute-api.ap-southeast-1.amazonaws.com/staging/books/{id}
