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.

  1. Create CodePipeline - Deploy stage role.

    • Open AWS IAM console, then click Roles on the left menu.
    • Click Create role button. CreatePipeline
    • 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. CreatePipeline
    • At Step 2: Add permissions page.
      • Enter AdministratorAccess at Search box.
      • Choose AdministratorAccess policy.
      • Then click Next button. CreatePipeline
    • At Step 3: Name, review, and create page.
      • Enter FCAJCodePipelineDeployStageRole at Role name. CreatePipeline
      • Scroll down and click Create role button. CreatePipeline
    • The role FCAJCodePipelineDeployStageRole is successfully created. CreatePipeline
  2. Create CodeBuild role.

    • Open AWS IAM console, then click Roles on the left menu.
    • Click Create role button. CreatePipeline
    • 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. CreatePipeline
    • At Step 2: Add permissions page.
      • Enter AdministratorAccess at Search box.
      • Choose AdministratorAccess policy.
      • Then click Next button. CreatePipeline
    • At Step 3: Name, review, and create page.
      • Enter FCAJCodeBuildRole at Role name. CreatePipeline
      • Scroll down and click Create role button. CreatePipeline
    • The role FCAJCodeBuildRole is successfully created. CreatePipeline

Create the pipeline

  1. Open AWS CodePipeline console.

    • Click Pipelines on the left menu.
    • Click Create pipeline button. CreatePipeline
  2. At Step 1: Choose creation option page.

    • Choose Build custom pipeline at Category.
    • Then click Next button. CreatePipeline
  3. 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. CreatePipeline
  4. At Step 3: Add source stage page.

    • Choose GitLab at Source provider.
    • Click the Connect to GitLab button. CreatePipeline
    • At Create a connection popup.
      • Enter FCAJBookStoreGitlabConnection at Connection name.
      • Click the Connect to GitLab button. CreatePipeline
      • At the GitLab authorization page, click the Authorize AWS Connector for GitLab button. CreatePipeline
      • After successful login to GitLab, click the Connect button. CreatePipeline
    • Check if the GitLab connection is successful.
    • Enter <your-username>/fcaj-book-store at Repository name.
    • Enter main at Default branch. CreatePipeline
    • Scroll down to the bottom and click the Next button. CreatePipeline
  5. At Step 4: Add build stage page.

    • Choose Other build providers at Build provider.
    • Choose the AWS CodeBuild.
    • Click the Create project button. CreatePipeline
    • At Create build project page at the new browser tab is just opened.
      • Enter FCAJBookStoreBuildProject at Project name. CreatePipeline
      • Scroll down, choose Ubuntu at Operating system.
      • Choose Existing service role at Service role.
      • Choose FCAJCodeBuildRole at Role ARN. CreatePipeline
      • Scroll down, choose Use a buildspec file at Build specifications. CreatePipeline
      • Scroll down to the bottom, click the Continue to CodePipeline button. CreatePipeline
    • The FCAJBookStoreBuildProject is successfully created in CodeBuild.
    • Leave as default and click the Next button. CreatePipeline
    • Choose United States (N. Virginia) at Region.
    • Scroll down and click the Next button. CreatePipeline
  6. At Step 5: Add test stage page.

    • Click the Skip test stage button. CreatePipeline
  7. 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. CreatePipeline
    • 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. CreatePipeline
  8. At Step 7: Review page.

    • Scroll down and click the Create pipeline button. CreatePipeline

Test the pipeline

  1. At FCAJBookStorePipeline page.

    • Wait for the pipeline to complete all stages: Source, Build, and Deploy. CreatePipeline
  2. Open API Gateway console.

    • You can see the fcaj-serverless-api has been created by the pipeline. CreatePipeline
  3. Click on the fcaj-serverless-api and choose Stages on the left menu.

    • Record the Invoke URL for later use. CreatePipeline