cloud technologies

Working with AWS and Powershell

As cloud technologies continue to converge and gain momentum, it is increasingly important to keep your skills as an administrator sharp. Luckily, both AWS and Microsoft have realized this, and in doing so have created some nice tools for working with cloud technologies and APIs.

In today’s post, I will cover a few key aspects of using the AWS Tools for PowerShell. If you aren’t already familiar, the AWS PowerShell tools are basically a set of scripts and modules (cmdlets) built on top of the AWS .NET toolkit. This allows for a tight integration between Windows and the AWS APIs as well as some nice flexibility that comes with PowerShell.

Getting Started with AWS Tools for PowerShell

Getting set up and started is easy. To install the AWS Tools for PowerShell make sure you are on at least PowerShell 5.1 to leverage all of the features. With PowerShell 5.1 the installation is as simple as running the following command. If you are using an older version of PowerShell you can find instructions for getting set up here.

>Install-Package -Name AWSPowerShell


NOTE: Make sure to run this from an elevated prompt, otherwise you will see errors.

powershell1

You can check the version to see if it was installed correctly. It does take a moment to load the first time.

>Get-AWSPowerShellVersion

powershell

Next, you will need to connect the AWS Tools on your local machine with your AWS account. I already had an access_id and access_key set up so just used those. If you haven’t ever worked with AWS keys/credentials, you will want to get your access keys all set up first.

> Set-AWSCredential -AccessKey xxxx -SecretKey xxxx

The credentials will be saved to a profile called “default.” You will want to setup your credentials to use this default profile that was just created.

>Set-AWSCredential -ProfileName default

Finally, you will want to initialize your configuration.

>Initialize-AWSDefaultConfiguration -ProfileName default -Region us-east-1

I used us-east-1 in my profile, but you can set this to default to another region if you use one. Additionally, you can supply the -Region flag in your commands to override the default region from configuration. You can find more about configuring and using regions here.

There is a default order that the AWS Tools uses to search for credentials, so if you configured things differently just be aware. The docs are pretty good, you can find them here. I found the CMDLET reference to be particularly useful for discovering how to use the examples I have written about in this post.

Using the AWS Tools

One useful thing that administrators do all the time is backups. Below, I will show a simple example of how you can interact with S3 object storage to copy some local files to AWS with PowerShell.

To create a new bucket use the following syntax,

> New-S3Bucket -BucketName josh-backup-test -Region us-west-1

Then you should be able to look at your bucket,

>Get-S3Bucket -bucketname josh-backup-test

Now you should be able to write some files to your bucket. Say, for example, that I have a text file on my local machine that I would like to upload to my bucket. The command for doing this is simple and straightforward.

>Write-S3Object -BucketName josh-backup-test -File test.txt

And if you check the AWS console, you should see the new test.txt file in your bucket. These tools can do a lot more, but in the interest of keeping things short and to the point, I’ll leave some of the other potential uses cases to the reader. Just know that basically anything that can be done from the AWS console can also be done via the command line with PowerShell, once the AWS Tools have been configured.

Wrapping Up on AWS and PowerShell

This is just a simple example to show some of the potential power and benefits of using a tool like this. The AWS Tools should be able to do basically everything that the AWS API can do, which means it could potentially be used to provision entire infrastructures if necessary.

At the very least, this tool can help to automate some of the simpler things that occur in the day-to-day sysadmin life. And hopefully, this example gets the gears turning for potential use cases in your own environments and infrastructures and allows readers the ability to automate even more things with Powershell.

Josh Tech Insight CTA

Want More Tech Insight?

SmartFile is a business file mangement platform that gives you more control, compliance and security.

TO SIGN UP