Create SAM pipeline
Preparation
In this step, we will create IAM roles for CodePipeline - Deploy stage, CodeBuild, and CodePipeline Service.
Warning
The role is configured with minimal security, suitable only for a workshop environment.
-
Create CodePipeline - Deploy stage role.
- Open AWS IAM console, then click Roles on the left menu.
- Click Create role button.

- At Step 1: Select trusted entity page.
- Choose AWS service at Trusted entity type.
- Enter
CloudFormation at Service or use case and choose CloudFormation at Use case.
- Then click Next button.

- At Step 2: Add permissions page.
- Enter
AdministratorAccess at Search box.
- Choose AdministratorAccess policy.
- Then click Next button.

- At Step 3: Name, review, and create page.
- Enter
FCAJCodePipelineDeployStageRole at Role name.

- Scroll down and click Create role button.

- The role FCAJCodePipelineDeployStageRole is successfully created.

-
Create CodeBuild role.
- Open AWS IAM console, then click Roles on the left menu.
- Click Create role button.

- At Step 1: Select trusted entity page.
- Choose AWS service at Trusted entity type.
- Enter
CodeBuild at Service or use case and choose CodeBuild at Use case.
- Then click Next button.

- At Step 2: Add permissions page.
- Enter
AdministratorAccess at Search box.
- Choose AdministratorAccess policy.
- Then click Next button.

- At Step 3: Name, review, and create page.
- Enter
FCAJCodeBuildRole at Role name.

- Scroll down and click Create role button.

- The role FCAJCodeBuildRole is successfully created.

Create the pipeline
-
Open AWS CodePipeline console.
- Click Pipelines on the left menu.
- Click Create pipeline button.

-
At Step 1: Choose creation option page.
- Choose Build custom pipeline at Category.
- Then click Next button.

-
At Step 2: Choose pipeline settings page.
- Enter
FCAJBookStorePipeline at Pipeline name.
- Choose Queued at Execution mode.
- Choose Existing service role at Service role.
- Choose FCAJCodePipelineServiceRole at Role ARN.
- Click the Next button.

-
At Step 3: Add source stage page.
- Choose GitLab at Source provider.
- Click the Connect to GitLab button.

- At Create a connection popup.
- Enter
FCAJBookStoreGitlabConnection at Connection name.
- Click the Connect to GitLab button.

- At the GitLab authorization page, click the Authorize AWS Connector for GitLab button.

- After successful login to GitLab, click the Connect button.

- Check if the GitLab connection is successful.
- Enter
<your-username>/fcaj-book-store at Repository name.
- Enter
main at Default branch.

- Scroll down to the bottom and click the Next button.

-
At Step 4: Add build stage page.
- Choose Other build providers at Build provider.
- Choose the AWS CodeBuild.
- Click the Create project button.

- At Create build project page at the new browser tab is just opened.
- Enter
FCAJBookStoreBuildProject at Project name.

- Scroll down, choose Ubuntu at Operating system.
- Choose Existing service role at Service role.
- Choose FCAJCodeBuildRole at Role ARN.

- Scroll down, choose Use a buildspec file at Build specifications.

- Scroll down to the bottom, click the Continue to CodePipeline button.

- The FCAJBookStoreBuildProject is successfully created in CodeBuild.
- Leave as default and click the Next button.

- Choose United States (N. Virginia) at Region.
- Scroll down and click the Next button.

-
At Step 5: Add test stage page.
- Click the Skip test stage button.

-
At Step 6: Add deploy stage page.
- Choose the AWS CloudFormation at Deploy provider.
- Choose United States (N. Virginia) at Region.
- Choose the BuildArtifact at Input artifacts.
- Choose the Create or update a stack at Action mode.
- Enter
fcaj-book-store at Stack name.

- Scroll down, choose BuildArtifact at Artifact name.
- Enter
packaged.yaml at File name.
- Choose the CAPABILITY_IAM, CAPABILITY_NAMED_IAM and CAPABILITY_AUTO_EXPAND at Capabilities - optional.
- Choose the FCAJCodePipelineDeployStageRole at Role name.
- Click the Next button.

-
At Step 7: Review page.
- Scroll down and click the Create pipeline button.

Test the pipeline
-
At FCAJBookStorePipeline page.
- Wait for the pipeline to complete all stages: Source, Build, and Deploy.

-
Open API Gateway console.
- You can see the fcaj-serverless-api has been created by the pipeline.

-
Click on the fcaj-serverless-api and choose Stages on the left menu.
- Record the Invoke URL for later use.
