- AWS
- Deploy to Google Cloud
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.
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.
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 Some credentials are required to be able to run Select your newly created user to access its details. Navigate to Security credentials > Create a new access key.
In your GitLab project, go to Settings > CI/CD. Set the following as
CI/CD variables
(see table below):
You can now use 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 provides a series of CI templates that you can include in your project.
To automate deployments of your application to your include the GitLab also provides
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:
After you have these prerequisites ready, follow these steps:
Add these variables to your project’s You can find these names after selecting the targeted cluster on your :
Alternatively, if you want to use a task definition defined in a JSON file, use
You can create your In both cases, make sure that the value for the Include this template in The Commit and push your updated Your application Docker image is rebuilt and pushed to the GitLab registry.
If your image is located in a private registry, make sure your task definition is
.
Then the targeted task definition is updated with the location of the new
Docker image, and a new revision is created in ECS as result.
Finally, your AWS ECS service is updated with the new revision of the
task definition, making the cluster pull the newest version of your
application.
Alternatively, if you don’t wish to use the
You can use the To run the The AWS documentation provides templates for the Create stack and Deploy to EC2 steps (links
below). We provide the template for the remaining step, Push to S3:
After you have completed these three templates based on your requirements, you
have two ways to pass in these JSON objects:
They can be three actual files located in your project. You must specify their path relative to
your project root in your Alternatively, you can provide these JSON objects as file-typed CI/CD variables.
In your project, go to Settings > CI/CD > Variables and add
the three variables listed above as file-typed CI/CD variables.
For each variable, set the value to its corresponding JSON object.
Provide the name of the stack you’re creating and/or targeting, as a CI/CD variable:
Add this CI template to your When running your project pipeline at this point:
To leverage Auto DevOps for your project when deploying to
AWS EC2, first you must define your AWS credentials as CI/CD variables.
Next, define a job for the
For a video walkthrough of this configuration process, see Auto Deploy to EC2.
If you didn't find what you were looking for,
search the docs.
If you want help with something specific and could use community support,
.
For problems setting up or using this feature (depending on your GitLab
subscription).AWS
Quick start
aws commands. As part of your deployment strategy, you can run aws commands directly from
.gitlab-ci.yml by specifying the .
aws commands:
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
aws commands on branches or tags that are not protected, make sure to uncheck the Protect variable checkbox.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 ...
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
.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)
AWS/Deploy-ECS.gitlab-ci.yml template in your .gitlab-ci.yml file.
registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest to use AWS CLI commands.
registry.gitlab.com/gitlab-org/cloud-deploy/aws-ecs:latest to deploy your application to AWS ECS.
<project-root>/ci/aws/task-definition.json.
.gitlab-ci.yml file, or in the project’s
CI/CD settings:
CI_AWS_ECS_CLUSTER: The name of the AWS ECS cluster that you’re targeting for your deployments.
CI_AWS_ECS_SERVICE: The name of the targeted service tied to your AWS ECS cluster.
CI_AWS_ECS_TASK_DEFINITION: The name of an existing task definition in ECS tied
to the service mentioned above.
variables:
CI_AWS_ECS_CLUSTER: my-cluster
CI_AWS_ECS_SERVICE: my-service
CI_AWS_ECS_TASK_DEFINITION: my-task-definition
CI_AWS_ECS_TASK_DEFINITION_FILE instead:
variables:
CI_AWS_ECS_CLUSTER: my-cluster
CI_AWS_ECS_SERVICE: my-service
CI_AWS_ECS_TASK_DEFINITION_FILE: ci/aws/my_task_definition.json
CI_AWS_ECS_TASK_DEFINITION_FILE variable as a
file-typed CI/CD variable instead of a
regular CI/CD variable. If you choose to do so, set the variable value to be the full contents of
the JSON task definition. You can then remove the JSON file from your project.
containerDefinitions[].name attribute is
the same as the Container name defined in your targeted ECS service.
CI_AWS_ECS_TASK_DEFINITION_FILE takes precedence over CI_AWS_ECS_TASK_DEFINITION if both these
variables are defined within your project..gitlab-ci.yml:
include:
- template: AWS/Deploy-ECS.gitlab-ci.yml
AWS/Deploy-ECS template ships with GitLab and is available on
GitLab.com.
.gitlab-ci.yml to your project’s repository, and you’re done!
AWS/Deploy-ECS.gitlab-ci.yml template. The “sub-templates” are designed to only be
used along with the main template. They may move or change unexpectedly causing your
pipeline to fail if you didn’t include the main template. Also, the job names within
these templates may change. Do not override these jobs names in your own pipeline,
as the override stops working when the name changes.AWS/Deploy-ECS.gitlab-ci.yml template
to deploy to AWS ECS, you can always use our
aws-base Docker image to run your own .
deploy:
stage: deploy
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
script:
- aws ecs register-task-definition ...
Provision and deploy to your AWS Elastic Compute Cloud (EC2)
AWS/CF-Provision-and-Deploy-EC2 CI template to perform the
following actions within the same pipeline:
Run the
AWS/CF-Provision-and-Deploy-EC2.gitlab-ci.yml template
AWS/CF-Provision-and-Deploy-EC2.gitlab-ci.yml template, you must
pass three JSON input objects, based on existing templates:
.gitlab-ci.yml file, using the following CI/CD variables. For example, if
your files are in a <project_root>/aws folder:
variables:
CI_AWS_CF_CREATE_STACK_FILE: 'aws/cf_create_stack.json'
CI_AWS_S3_PUSH_FILE: 'aws/s3_push.json'
CI_AWS_EC2_DEPLOYMENT_FILE: 'aws/create_deployment.json'
variables:
CI_AWS_CF_STACK_NAME: 'YourStackName'
.gitlab-ci.yml:
include:
- template: AWS/CF-Provision-and-Deploy-EC2.gitlab-ci.yml
CI_AWS_CF_CREATE_STACK_FILE file/variable.
If your stack already exists, this step is skipped, but the provision job it belongs to still
runs.
Custom build job for Auto DevOps
build stage. To do so, you must reference the
Auto-DevOps.gitlab-ci.yml template and include a job named build_artifact in your
.gitlab-ci.yml file. For example:
# .gitlab-ci.yml
include:
- template: Auto-DevOps.gitlab-ci.yml
variables:
AUTO_DEVOPS_PLATFORM_TARGET: EC2
build_artifact:
stage: build
script:
- <your build script goes here>
artifacts:
paths:
- <built artifact>
Deploy to Amazon EKS
Deploy to Google Cloud
Help & feedback
Docs
Edit this page
to fix an error or add an improvement in a merge request.
Create an issue
to suggest an improvement to this page.
Product
Create an issue
if there's something you don't like about this feature.
Propose functionality
by submitting a feature request.
to help shape new features.
Feature availability and product trials
to see all GitLab tiers and features, or to upgrade.
with access to all features for 30 days.
Get Help

