Using AWS CodePipeline and AWS CodeStar Connections to deploy from Bitbucket
AWS CodeStar Connections is a new feature that allows services like AWS CodePipeline to access third-party code source provider. For example, you can now seamlessly connect your Atlassian Bitbucket Cloud source repository to AWS CodePipeline. This allows you to automate the build, test, and deploy phases of your release process each time a code change occurs.
This new feature is available in the following Regions:
- US East (Ohio)
- US East (N. Virginia)
- US West (N. California)
- US West (Oregon)
- Asia Pacific (Mumbai)
- Asia Pacific (Seoul)
- Asia Pacific (Singapore)
- Asia Pacific (Sydney)
- Asia Pacific (Tokyo)
- Canada (Central)
- EU (Frankfurt)
- EU (Ireland)
- EU (London)
- EU (Paris)
- South America (São Paulo)
The practice of tracking and managing changes to code, or source control, is a foundational element to the development process. Therefore, source control management systems are an essential tool for any developer. In this post, we focus on one specific Git code management product: Atlassian Bitbucket. You can get started for free with Bitbucket Cloud.
Atlassian provides detailed documentation on getting started with Bitbucket Cloud, which includes topics such as setting up a team, creating a repository, working with branches, and more. For more information, see Get started with Bitbucket Cloud.
For this use case, you use a Bitbucket account, repository, and Amazon Simple Storage Service (Amazon S3) bucket that we have already created. To follow along, you should have the following:
- A working knowledge of Git and how to fork or clone within your source provider
- Familiarity with hosting a static website on Amazon S3
To follow along you will need a sample page. Here is some simple html code that you can name index.html and add to your repo.
<html> <head> Example Header </head> <body> Example Body Text </body> </html>
For this use case, you deploy a Hugo website from your Bitbucket Cloud repository to your S3 bucket using CodePipeline. You can then connect your Bitbucket Cloud account to your AWS account to deploy code natively.
The walkthrough contains the following steps:
- Set up CodeStar connections.
- Add a deployment stage.
- Use CI/CD to update your website.
Setting up CodeStar connections
When connecting CodePipeline to Bitbucket Cloud, it helps if you already signed in to Bitbucket. After you sign in to Bitbucket Cloud, you perform the rest of the connection steps on the AWS Management Console.
- On the console, search for CodePipeline.
- Choose CodePipeline.
- Choose Pipelines.
- Choose Create pipeline.
- For Pipeline name, enter a name.
- For Service role, select New service role.
- For Role name, enter a name for the service role.
- Choose Next.
- For Source provider, choose Bitbucket Cloud.
- For Connection, choose Connect to Bitbucket Cloud.
- For Connection name, enter a name.
- For Bitbucket Cloud apps, choose Install a new app.
If this isn’t your first time making a connection, you can choose an existing connection.
- Choose Connect.
- Confirm you’re logged in as the correct user and choose Grant access.
- Choose Connect.
- For Repository name, choose your repository.
- For Branch name, choose your branch.
- For Output artifact format, select CodePipeline default.
- Choose Next.
Adding a deployment stage
Now that you have created a source stage, you can add a deployment stage.
- On the Add build stage page, choose Skip build stage.For this use case, you skip the build stage, but if you need to build your own code, choose your build provider from the drop-down menu.You are prompted to confirm you want to skip the build stage.
- Choose Skip.
- For Deploy provider, choose Amazon S3. If you have a different destination type or are hosting on traditional compute, you can choose other providers.
- For Region, choose the Region your S3 bucket is in.
- For Bucket, choose the bucket you are deploying to.
- Optionally, you can also choose a deploy path if you need to deploy to a sub-folder.
- Select Extract file before deploy.
- Choose next.
- Review your configuration and choose Create pipeline.
If the settings are correct, you see a green success banner and the initial deployment of your pipeline runs successfully. The following screenshot shows our first deployment.
Now that the pipeline shows that the deployment was successful, you can check the S3 bucket to make sure the site is being hosted. You should see your static webpage, as in the following screenshot.
Using CI/CD to update our website
Now that you have created your pipeline, you can edit your website using your IDE, push the changes, and validate that those changes are automatically deployed to the website. For this step, I already cloned my repository and have it opened in my IDE.
- Open your code in your preferred IDE.
- Make the change to your code and push it to Bitbucket.The following screenshot shows that we updated the message that viewers see on our website and pushed our code.
- Look at the pipeline and make sure your code is being processed.
The following screenshot shows that the stages were successful and the pipeline processed the correct commit.
After your pipeline is successful, you can check the end result. The following screenshot shows our static webpage.
If you created any resources during this that you do not plan on keeping, make sure you clean it up to keep from incurring cost associated with the services.
Being able to let your developers use their repository of choice can be important in your transition to the cloud. CodeStar connections makes it easy for you to set up Bitbucket Cloud as a source provider in the AWS Code Suite.
Get started building your CI/CD pipeline using Bitbucket Cloud and the AWS Code Suite.