Deploy to Amazon AWS

This guide will help you configure your Bitbucket Pipelines deployment to AWS with Elastic Beanstalk, CodeDeploy and S3.

You may also be interested in this guide: Deploy to Amazon ECS.

See these repos too:

Add your AWS credentials to Bitbucket Pipelines

Before we start with the deployment instructions you'll need to add 2 environment variables to Bitbucket Pipelines so it can interact with your AWS account:

  • AWS_ACCESS_KEY_ID: Your AWS access key.
  • AWS_SECRET_ACCESS_KEY: Your AWS secret access key. Make sure that you save it as a secured variable.

Deploy to AWS with Elastic Beanstalk

You can use the Elastic Beanstalk CLI to deploy your application to your Elastic Beanstalk environment. If it's not yet installed on the Docker image that you are using for your pipeline you can simply install it with Python using pip.

pip install awsebcli --upgrade

You may have to install pip as part of your pipeline –  do that by replicating the configuration below which is based on Node.

image: node:7.5.0

pipelines:
  default:
    - step:
        script:
          - apt-get update && apt-get install -y python-dev
          - curl -O https://bootstrap.pypa.io/get-pip.py
          - python get-pip.py
          - pip install awsebcli --upgrade

Now that the client is installed you just need to initialize your Elastic Beanstalk configuration and run the eb deploy command to deploy your code to your environment of choice. A complete pipeline configuration should look like the following YML.

image: node:7.5.0

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - npm install
          - npm test
          - apt-get update && apt-get install -y python-dev
          - curl -O https://bootstrap.pypa.io/get-pip.py
          - python get-pip.py
          - pip install awsebcli --upgrade
          - eb init <Application name> -r <AWS region> -p <Application platform>
          - eb deploy <Environment name>

Just replace the following variables by the corresponding values for your AWS configuration:

  • <Application name>: Name of your Elastic Beanstalk application
  • <AWS region>: Region where your application is configured
  • <Application platform>: Platform that you are using to run your application (Node, PHP, etc...)
  • <Environment name>: Name of the environment that you want to deploy to.

You can check your bitbucket-pipelines.yml file with our online validator.

Deploy to AWS with CodeDeploy

In this section we will assume that you already have AWS CodeDeploy configured and that you have the following information:

  • Application name
  • S3 bucket where you store your application code
  • Application deployment group

You can easily trigger a deployment from Bitbucket Pipelines using the AWS CLI. You will use it to first push your build to a S3 bucket and then tell CodeDeploy to promote a new version in production by taking the build from the corresponding S3 bucket.

If the Docker image that you're using in your pipeline does not yet have the AWS CLI you can easily install it with Python using pip.

pip install awscli

You may have to install pip as part of your pipeline – you can do this by replicating the configuration below which is based on Node.

image: node:7.5.0

pipelines:
  default:
    - step:
        script:
          - apt-get update && apt-get install -y python-dev
          - curl -O https://bootstrap.pypa.io/get-pip.py
          - python get-pip.py
          - pip install awscli

You can adapt the code below to set up your CodeDeploy deployment by replacing the following values:

  • <Application name>: Name of your CodeDeploy application 
  • <S3 bucket>: Name of your S3 bucket
  • <S3 key>: Reference under which your build will be stored
  • <Deployment group>: Name of the deployment group your build should be deployed to.

You can edit and check your bitbucket-pipelines.yml file with our online validator.

 

image: node:7.5.0

pipelines:
  default:
    - step:
        script:
          - apt-get update && apt-get install -y python-dev
          - curl -O https://bootstrap.pypa.io/get-pip.py
          - python get-pip.py
          - pip install awscli
          - aws deploy push --application-name <Application name> --s3-location s3://<S3 bucket>/<S3 key> --ignore-hidden-files
          - aws deploy create-deployment --application-name <Application name> --s3-location bucket=<S3 bucket>,key=<S3 key>,bundleType=zip --deployment-group-name <Deployment group>


Deploy to AWS with S3

If you're hosting a static website with S3 you can use the AWS CLI to update your website with Bitbucket Pipelines with the aws s3 sync command.

If the Docker image that you're using in your pipeline does not yet have the AWS CLI you can easily install it with Python using pip.

pip install awscli

You may have to install pip as part of your pipeline – you can do this by replicating the configuration below which is based on Node.

image: node:7.5.0

pipelines:
  default:
    - step:
        script:
          - apt-get update && apt-get install -y python-dev
          - curl -O https://bootstrap.pypa.io/get-pip.py
          - python get-pip.py
          - pip install awscli

To update your website you just need to sync your repository with your S3 bucket. You can use the --delete flag to make sure that files that aren't needed anymore get removed from your S3 bucket. Just adapt the example below and replace <S3 bucket> with your own.

image: node:7.5.0

pipelines:
  default:
    - step:
        script:
          - apt-get update && apt-get install -y python-dev
          - curl -O https://bootstrap.pypa.io/get-pip.py
          - python get-pip.py
          - pip install awscli
          - aws s3 sync --delete . s3://<S3 bucket>

 

You can check your bitbucket-pipelines.yml file with our online validator.

最終更新日 2017 年 11 月 6 日

この翻訳に満足しましたか?

はい
いいえ
この記事についてのフィードバックを送信する

お探しの情報が見つかりませんか?

コミュニティへの質問

Powered by Confluence and Scroll Viewport.