Setting AWS Credentials in GitHub Actions
Last Updated :
17 Apr, 2024
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 that your AWS resources and GitHub repositories integrate seamlessly, giving you the ability to automate testing, deployment, and other tasks right from your CI/CD pipelines. We will go over how to safely configure your AWS credentials in GitHub Actions so you can use all of AWS's capabilities in your automated processes. GitHub has a robust automation tool called GitHub Actions that allows you to automate processes from inside your repository. It facilitates process optimization by automating code-building, code testing, and code deployment. With the help of GitHub Actions, you can design complex CI/CD pipelines and automate difficult procedures inside the well-known GitHub environment. To learn more about configuring the credentials on Git Hub actions, follow the steps mentioned below.
Step-By-Step To Configure AWS Credentials In GitHub Actions
Step 1: Create the GitHub repository
Step 2: Click on the repository settings, then click on the secrets and variables section, then click on actions, then click on the new repository secret as shown in the image below.

Step 3: Here we are configuring the AWS_ACCESS_KEY_ID in the secrets section for your reference refer the below image. Here I have configured the sample secret. For more information regarding to get the secret credentials about in AWS refer this link.

Step 4: Here is the secrets is configured on Git hub plaese refer the below screenshot.

Step 5: This is the git hub action file to call the secrets into the action file refer the below CI/CD file.
name: AWS Deployment
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Deploy to AWS
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws s3 cp ./dist s3://example-bucket --recursive
This GitHub Actions workflow file is named "AWS Deployment" and is triggered on pushes to the main branch. It runs on an Ubuntu latest environment. The job "deploy" consists of two steps:
- "Checkout code": Uses the GitHub Actions official action to checkout the repository's code.
- "Deploy to AWS": Executes a series of AWS CLI commands to configure AWS credentials using secrets, and then copies the contents of the "./dist" directory to an S3 bucket named "example-bucket" recursively.
This workflow automates the deployment of the code to an AWS S3 bucket whenever changes are pushed to the main branch.
In the provided GitHub Actions workflow file for AWS Deployment, AWS secrets are utilized for configuring AWS access credentials securely. The secrets used are:
AWS_ACCESS_KEY_ID
: This secret stores the AWS access key ID.AWS_SECRET_ACCESS_KEY
: This secret stores the AWS secret access key.
These secrets are accessed using the ${{ secrets.NAME }}
syntax, ensuring that sensitive information is not exposed in the workflow file itself. Instead, these secrets are stored securely in the GitHub repository settings and are only accessible to authorized users with appropriate permissions. This approach helps maintain the security of AWS credentials while enabling automated deployment processes.
Step 6: Here is the console output of the GitHub action CI/CD.

Conclusion
It is essential that you securely configure your AWS credentials in GitHub Actions to allow smooth communication between your workflows and AWS services. You can make sure that your automation processes are prepared to deploy, test, and manage AWS resources effectively and securely by following the above step-by-step guide. By utilizing GitHub Secrets to securely configure your AWS credentials, you can fully utilize their capabilities in your CI/CD pipelines while protecting the confidentiality and integrity of your important credentials.
Similar Reads
How to use AWS CLI in GitHub Actions ?
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
4 min read
How to Add GIT Credentials in Jenkins?
Git is a famous distributed version control system. Version Control Systems are mainly two types. Distributed & Centralised Version Control System. Centralized Version Control Systems are older & very hectic to use. That is why Distributed Version Control Systems are nowadays very famous for
5 min read
How to Add GIT Credentials in VS Code?
Git is a version management system for computer files that track changes. It is commonly used in software development for source code management. It is intended to handle any form of project, large or little, with speed and efficiency. It focuses on distributed software development so that additiona
3 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
How to Add Git Credentials in Linux?
Git is a commonly used free and open-source version control system. It's a tool used for source code management. It is used to handle from very small projects to very large projects with great efficiency. In git, a version control system records all the changes that are made to the source code over
3 min read
How to Add GIT Credentials in MacOS?
Git is an essential tool for developers, enabling them to manage their codebase and collaborate with others effectively. To interact with remote repositories on platforms like GitHub, GitLab, or Bitbucket, you need to authenticate using your Git credentials. This article will guide you through the p
3 min read
How to Get Current Branch name in GitHub Actions
GitHub Actions rightfully deserves credit for the way the workflow automation in the GitHub is being redefined. No matter it has been about continuous integration, deployment or the automation of any custom operation, GitHub Actions provide a framework that is advanced enough to make these tasks eas
4 min read
How to Add GIT Credentials on Windows?
Managing Git credentials on Windows is important for seamless interaction with remote repositories. Whether you're pushing code to GitHub, GitLab, or another Git service, storing your credentials securely can save you from repeatedly entering your username and password. This article will walk you th
2 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 Add Git Credentials in Eclipse?
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It is used for tracking changes in project files done by multiple developers and programmers. And Eclipse is one of the most popular integrated
2 min read