Using AWS Amplify and Bitbucket Pipelines for CICD

Amplifying my deployment capabilities

After more than 20 years of Apache config wrangling, I have moved all of my web properties to AWS Amplify. I am also back to using Bitbucket Pipelines for Continuous Integration / Continuous Delivery (CI/CD).

All of my web sites are static pages, for the simplicity and security this provides. I like to keep things boring when I can. I also use Hugo to generate content from Markdown.

As a result, I am using AWS Amplify for its static hosting capabilities.

My git repositories are all on Bitbucket. Each repo uses a Bitbucket pipeline to do some or all of:

  • build the site content via Hugo in a Docker container
  • serve the content on a specified port on localhost
  • run Linkcheck against the site to verify links
  • run BDD via Python Behave to verify behaviour
  • trigger deployment to AWS Amplify

When I added each site to AWS Amplify, I needed to do a few things:

  • under App settings -> Branch settings, disabled the auto-build - since Bitbucket is the builder
  • under Hosting -> Build settings, created an incoming webhook - so I can trigger deployments from Bitbucket

I then configured Bitbucket to use the Amplify webhook. The webhook curl command is of the form:

curl -X POST -d {} \
 "https://webhooks.amplify.amazonaws.com/prod/webhooks?\
 id=$AWS_WEBHOOK_ID&token=$AWS_WEBHOOK_TOKEN&operation=startbuild" \
 -H "Content-Type:application/json"

where AWS_WEBHOOK_ID and AWS_WEBHOOK_TOKEN are generated by AWS Amplify. Because I don’t want these floating around everywhere, I created a pair of secured variables in Bitbucket:

  • repository settings -> repository variables, add secured variable

Then the bitbucket-pipelines.yml Deployment step can simply be as shown above. Bitbucket takes care of masking the secured variables.

And voila: every time I push to bitbucket, and the pipeline succeeds, it triggers AWS Amplify to deploy!

In addition, I am now using Bitbucket’s Deployments to provide status of my environments. The syntax for the step is:

- step:
        name: "Deploy to production"
        deployment: production
        script:
            - curl -X POST -d {} ...

Bitbucket Deployments show the history of when commits were deployed.