How to use AWS CLI in GitHub Actions ?
Last Updated :
30 Apr, 2024
Through a command-line interface, Amazon offers a powerful tool called the Amazon Web Services Command Line Interface, or AWS CLI, which makes managing AWS resources easier. The importance of this is that it can simplify the process of utilizing AWS services straight from the terminal, removing the requirement to go through the AWS Management Console. Developers, system administrators, and DevOps engineers, who frequently carry out repeated operations and must automate workflows, will find this efficiency very beneficial. Users may configure S3 buckets, manage IAM users and permissions, provision and manage EC2 instances, and execute a plethora of other tasks with complete control over AWS resources using the AWS CLI. It can easily integrate with other command-line tools thanks to its adaptability and integration features.
Step-by-step use GitHub Action - AWS CLI
Step 1: Create a GitHub repository.
Step 2: Here is the repository called as aws-cli-in-github-actions. For your reference, refer the below image.

Step 3: Configure the aws credentials on secrets section as shown image below. Get the aws credentials using the IAM roles or user.

Step 4: Create the S3 bucket.
Step 5: Write the gihub acion file and keep it in the path of .github/workflows I have named it as a blank.yml. Here is the my sample github action file to copy the file from the local to S3.
name: aws cli in github actions
on:
workflow_dispatch:
jobs:
aws-cli-in-github-actions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install awscli
- run: |
ls -lrth
chmod 777 /home/runner/work/bash-script/bash-script/README.md
ls -lrth /home/runner/work/bash-script/bash-script
aws --version
pwd
aws s3 cp /home/runner/work/bash-script/bash-script/README.md s3://demosamples3 --region us-east-2 --cache-control max-age=0
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- Name and Trigger:
- The workflow is named "aws cli in github actions".
- It is triggered manually through the GitHub web interface using the
workflow_dispatch
event.
- Jobs:
- There is one job defined in this workflow named "aws-cli-in-github-actions".
- This job runs on an Ubuntu latest environment.
- Steps:
- Checkout Code:
- This step uses the
actions/checkout@v2
action to check out the repository's code.
- Setup Python:
- This step uses the
actions/setup-python@v2
action to set up Python. - Python version 3.10 is specified.
- Install Dependencies:
- This step installs the AWS CLI dependencies.
- It upgrades pip and installs the
awscli
package using pip.
- Run AWS CLI Commands:
- This step runs AWS CLI commands to interact with AWS services.
- It lists files in the directory, changes permissions of the README.md file, lists files again to verify changes, checks the AWS CLI version, prints the current directory, and finally copies the README.md file to an S3 bucket (
demosamples3
) with specified region (us-east-2
) and cache-control settings.
- Environment Variables:
- AWS credentials (access key ID and secret access key) are provided as environment variables using GitHub Secrets (
AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
). - These credentials are used by the AWS CLI to authenticate and authorize actions performed in the AWS environment.
Step 6: Click on the action tab and you will find the github action file.

Step 7: Click on the aws cli in github action and trigger the action file. The pipeline successfully executed on the gihub using the aws cli.

Step 8: Here is the detail console output of the action file. The file successfully uploaded into the S3 bucket.

Step 9: Here is the proof the file into S3. For your reference refer the below image.

Conclusion
AWS CLI plays a vital role in simplifying the management of AWS resources through a command-line interface. By integrating AWS CLI with GitHub Actions, developers, system administrators, and DevOps engineers can automate workflows and streamline cloud management tasks. The step-by-step guide presented in this article demonstrates how to set up AWS CLI in GitHub Actions, perform various AWS operations, and seamlessly integrate them into existing workflows. With AWS CLI and GitHub Actions, users gain efficiency, flexibility, and control over managing AWS resources, empowering them to work more effectively in the cloud. By following the outlined steps, users can harness the power of AWS CLI within their GitHub workflows, enabling seamless deployment, automation, and management of cloud resources."
Similar Reads
How do I use Docker with GitHub Actions? Docker packages all the components required for software into containers, much like a recipe box. By automating chores in your development workflow, GitHub Actions serves as your personal chef. When combined, they optimize software development by effectively packaging applications and smoothly autom
5 min read
How to Run Bash Script in Github Actions ? GitHub Actions are helpful resources for coding. They automate processes in your GitHub projects, save you time and effort. It is possible that GitHub Actions will automate the steps involved in testing, deploying, and alerting users of your code. Because you can configure them to run at specified t
5 min read
How to Delete GitHub Actions Cache ? Resources or dependencies that you regularly utilize in your workflows can be temporarily stored in the GitHub Actions cache. The GitHub Actions the cache significantly speeds up the workflow execution by reuse these files and eliminate the need to rebuild dependencies or download them each time a p
5 min read
Setting AWS Credentials in GitHub Actions Putting your AWS credentials in GitHub Actions is essential to enabling safe and effective interactions between your workflows and AWS services. Your processes can authenticate and send API queries to AWS services like S3, EC2, or Lambda by giving the required access credentials. This makes sure tha
4 min read
How to Add GitHub Actions Secrets ? When it comes to safely managing sensitive data in your workflowsâlike access tokens, API keys, and other credentialsâGitHub Actions secrets are essential. By using these tricks, you can securely access and save private information without exposing it to the source code of your repository. You may i
5 min read
How to Skip a Job in GitHub Actions ? With the help of GitHub Actions, developers can effectively automate a range of processes and workflows right within their repositories. You can develop, test, and publish your code using GitHub Actions without ever leaving the GitHub website. It provides an adaptable and configurable workflow frame
6 min read