Create SAM pipeline

Preparation

In this step, we will create IAM roles for CodePipeline - Deploy stage and CodeBuild.

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 fcjCodePipelineDeployStageRole at Role name. CreatePipeline
      • Scroll down and click Create role button. 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 fcjCodeBuildRole at Role name. CreatePipeline
      • Scroll down and click Create role button. 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 Creation options.
    • Then click Next button. CreatePipeline
  3. At Step 2: Choose pipeline settings page.

    • Enter fcjBookStorePipeline at Pipeline name.
    • Choose Queued at Execution mode.
    • Choose New service role at Service role.
    • Enter AWSCodePipelineServiceRole-us-east-1-fcjBookStorePipeline at Role name.
    • 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 page at new browser tab is just opened.
      • Enter fcjBookStoreGitlabConnection at Connection name.
      • Click the Connect to Gitlab button. CreatePipeline
      • After successful login to Gitlab, click the Connect button. CreatePipeline
    • Check if the Gitlab connection is successful.
    • Enter fcj-ws/fcj-book-store-backend at Repository name.
    • Enter master 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 fcjBookStoreBuildProject at Project name. CreatePipeline
      • Scroll down, choose Ubuntu at Operating system.
      • Choose Existing service role at Service role.
      • Choose fcjCodeBuildRole at Role ARN. CreatePipeline
      • Scroll down to the bottom, choose Use a buildspec file at Build specifications.
      • Click the Continue to CodePipeline button. CreatePipeline
    • Choose the fcjBookStoreBuildProject at Project name.
    • Leave as default 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 the BuildArtifact at Input artifacts.
    • Choose the Create or update a stack at Action mode.
    • Enter fcj-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 fcjCodePipelineDeployStageRole 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. Open AWS CodePipeline console.

    • Click Pipelines on the left menu.
    • Choose fcjBookStorePipeline pipeline. CreatePipeline
  2. At fcjBookStorePipeline page.

    • Scroll down to the bottom, click the View details button. CreatePipeline
  3. At fcjBookStorePipeline - Deploy stage page.

    • Choose the Output tab and record the ApiUrl. CreatePipeline