AWS Tools for PowerShell module in GitHub Actions

Previously, I wrote a note on using AWS Tools for PowerShell in Azure Pipelines, and in this note, I show how to use that in GitHub Actions. If you are new to AWS Tools for Powershell, I recommend reading about that at AWS Docs.

The process can be broken down into three steps:
1. Configure AWS Credentials
2. Install the necessary modules, and
3. Use AWS Tools for the PowerShell module command
If you are interested, you can follow along by accessing the code stored in my GitHub repo: TestProjects, and the GitHub Actions pipeline: install-aws-tools-ps.

Step 1: Configure AWS Credentials
I used the Configure AWS Credentials action with my GitHub Actions pipeline to manage the IAM aspect -authentication and authorization- for the pipeline. This step enables GitHub Actions to acquire short-term AWS credentials to communicate with the AWS cloud. I have a detailed note on this concept covered in my note at –securely-integrate-aws-credentials-with-github-actions-using-openid-connect.

Step 2: Install the necessary modules
All the modules listed in the aws-ps-modules.json are checked and installed by the idempotent logic in the InstallAWSTools.ps1 PowerShell file (access GitHub repo here). And the PowerShell file is referenced in the GitHub Actions pipeline via the block below:
75-image-2
Step 3: Use AWS Tools for the PowerShell module command
This is an example step to demonstrate that the GitHub Actions pipeline can securely communicate with the AWS cloud. The step below checks if an Amazon S3 bucket by that name exists and returns true if the bucket exists or false.
75-image-3
The step uses the Test-S3Bucket Cmdlet to check that. This step would have errored if I had not correctly set the Configure AWS Credentials (Step 1) and had not installed the AWS Tools for PowerShell module (Step 2). I wanted to use the S3 cmdlet and specified the required PowerShell module (AWS.Tools.S3) in the aws-ps-modules.json file. If your use case demands interaction with other AWS resources, please add them accordingly. For a list of all AWS resources, you can access – PowerShellGallery-AWS.Tools.

As you might have noted, I did not add a step in the GitHub Actions pipeline to remove the credentials; the Configure AWS Credentials Action automatically triggers that step. Please check the pipeline log run to verify.

And that is how to use AWS Tools for PowerShell module in GitHub Actions. I hope you found this note valuable. I use this logic often, so if you have any questions, please do not hesitate to reach out.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s