Cloud deployment

Interacting with a major cloud provider may have become a much needed task that’s part of your delivery process. With GitLab you can .

For some specific deployment targets, GitLab makes this process less painful by providing Docker images with the needed libraries and tools pre-installed. By referencing them in your CI/CD pipeline, you can interact with your chosen cloud provider more easily.

AWS

GitLab provides Docker images that you can use to run AWS commands from GitLab CI/CD, and a template to make it easier to deploy to AWS.

Quick start

If you’re using GitLab.com, see the quick start guide for setting up Continuous Deployment to Run AWS commands from GitLab CI/CD

The GitLab AWS Docker image provides the , which enables you to run aws commands. As part of your deployment strategy, you can run aws commands directly from .gitlab-ci.yml by specifying the .

Some credentials are required to be able to run aws commands:

  1. Sign up for Log in onto the console and create .
  2. Select your newly created user to access its details. Navigate to Security credentials > Create a new access key.

    note
    A new Access key ID and Secret access key are generated. Please take a note of them right away.
  3. In your GitLab project, go to Settings > CI/CD. Set the following as CI/CD variables (see table below):

    Environment variable name Value
    AWS_ACCESS_KEY_ID Your Access key ID
    AWS_SECRET_ACCESS_KEY Your Secret access key
    AWS_DEFAULT_REGION Your region code
    note
    When you create a variable it’s set to be protected by default. If you want to use the aws commands on branches or tags that are not protected, make sure to uncheck the Protect variable checkbox.
  4. You can now use aws commands in the .gitlab-ci.yml file of this project:

    deploy:
      stage: deploy
      image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest  # see the note below
      script:
        - aws s3 ...
        - aws create-deployment ...
    
    note
    The image used in the example above (registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest) is hosted on the GitLab Container Registry and is ready to use. Alternatively, replace the image with one hosted on AWS ECR.

Use an AWS Elastic Container Registry (ECR) image in your CI/CD

Instead of referencing an image hosted on the GitLab Registry, you can reference an image hosted on any third-party registry, such as the .

To do so, . Then reference it in your .gitlab-ci.yml file and replace the image path to point to your ECR image.

Deploy your application to the AWS Elastic Container Service (ECS)

GitLab provides a series of CI templates that you can include in your project. To automate deployments of your application to your include the AWS/Deploy-ECS.gitlab-ci.yml template in your .gitlab-ci.yml file.

GitLab also provides

  • Use registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest to use AWS CLI commands.
  • Use registry.gitlab.com/gitlab-org/cloud-deploy/aws-ecs:latest to deploy your application to AWS ECS.

    Before getting started with this process, you need a cluster on AWS ECS, as well as related components, like an ECS service, ECS task definition, a database on Amazon RDS, and so on. .

    The ECS task definition can be: