In this step, we add the necessary parameters and API Gateway resource definitions to template.yaml, then deploy the SAM stack so that the REST API skeleton is ready before we attach individual HTTP methods in the following sections.
Open template.yaml in the fcj-book-shop folder.
Inside the Parameters: section, append the four new parameters shown below. These values will be referenced by the API Gateway resources we create next.
apiType:
Type: String
Default: REGIONAL
binaryMediaType:
Type: String
Default: multipart/form-data
getOrPostPathPart:
Type: String
Default: books
deletePathPart:
Type: String
Default: "{id}"

Inside the Resources: section (below the existing Lambda and S3 resources), add the following three resources:
fcj-serverless-api with a Regional endpoint and multipart/form-data binary media type support./books path resource under the API root./{id} path resource under /books, used for DELETE operations.BookApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: fcj-serverless-api
EndpointConfiguration:
Types:
- !Ref apiType
BinaryMediaTypes:
- !Ref binaryMediaType
BookApiResource:
Type: AWS::ApiGateway::Resource
Properties:
RestApiId: !Ref BookApi
ParentId: !GetAtt BookApi.RootResourceId
PathPart: !Ref getOrPostPathPart
BookDeleteApiResource:
Type: AWS::ApiGateway::Resource
Properties:
RestApiId: !Ref BookApi
ParentId: !Ref BookApiResource
PathPart: !Ref deletePathPart

Run the following commands in your terminal to validate, build, and deploy the updated stack:
sam validate
sam build
sam deploy
sam validate checks the template for syntax errors.sam build packages the Lambda functions and resolves dependencies.
sam deploy uploads the template and shows the CloudFormation changeset. Confirm with y when prompted.BookApi, BookApiResource, and BookDeleteApiResource.
UPDATE_COMPLETE. The output should read “Successfully created/updated stack - fcaj-book-shop in ap-southeast-1”.
Open the Amazon API Gateway console.

Click fcaj-serverless-api → Resources in the left sidebar.
Path: /books.
Path: /books/{id}.
Click API settings in the left sidebar.
multipart/form-data is listed. This is required for image file uploads via the POST API.
The preparation steps are complete. The API skeleton (/books and /books/{id} resources) is now deployed. In the next sections, we will attach GET, POST, and DELETE methods to these resources.