I'm working on converting our shared credential file to use the SDK Store (encrypted) for managing AWS credentials on our onsite Windows machines using PowerShell. In the shared credential file, I could specify a region for each set of credentials, but I can't find a way to do that with the Set-AWSCredential command. Specifically, the -Region parameter seems to cause an error. I'm looking for solutions that would work on both EC2 instances and on-premises devices like laptops or QA systems. Any thoughts or suggestions would be greatly appreciated!
2 Answers
Have you tried using the command:
```
Set-DefaultAWSRegion -Region us-west-2
```
This should set the default region for your commands. You can check the AWS documentation [here](https://docs.aws.amazon.com/powershell/latest/userguide/pstools-installing-specifying-region.html) for more details!
You can actually handle it in two steps! First, store your credentials, and then set the default region separately. For example:
```
Set-AWSCredential -AccessKey "myac" -SecretKey "mysc" -StoreAs "pname"
Initialize-AWSDefaultConfiguration -ProfileName pname -Region us-east-1
Get-SQSQueue -ProfileName pname
```
This way you're able to apply the region when using the profile, no issues with the queues being returned based on that region!
Thanks for the tip! I actually realized that I need the region to be set in the credential profile since I'm calling the credentials via an API. The shared cred file has this structure:
```
[profileName]
aws_access_key_id = ANOTHER_ACCESS_KEY_ID
aws_secret_access_key = ANOTHER_SECRET_ACCESS_KEY
region = us-east-1
```
I need to ensure the region is also stored in the SDK Store when adding the profile. Any ideas how to do this?