Credential Error when trying to use Write-S3Object

0

I need to upload some large files to an S3 bucket which I've done in the past, but I've lost my notes since then. I am using PowerShell and I've got the module installed and imported. I've logged in, set the region, but when I try to write it tells me No credentials specified or obtained from persisted/shell defaults. I thought maybe the credentials I was using were old, so I created new ones, but I get the same error.

What am I missing/doing wrong?

Install-Module -Name AWSPowerShell.NetCore

Set-ExecutionPolicy RemoteSigned

Import-Module AWSPowerShell.NetCore

Set-AWSCredential -AccessKey MyAccessKey -SecretKey MySecretKey -StoreAs myProfileName

Set-DefaultAWSRegion -Region us-east-1

Get-EC2Instance -ProfileName MyProfileName

Write-S3Object -BucketName "MyBucketName" -Key "gfi/2013 Jul - Sep.mdf" -File "F:\SQLDB\TO_AWS\2013 Jul - Sep.mdf"

Yes, I am using my actual Bucket Name, Access Key, and Secret Key.

FULL ERROR Write-S3Object : No credentials specified or obtained from persisted/shell defaults. At line:1 char:1 Write-S3Object -BucketName "MyBucketName" -Key "gfi/2013 Jul - Sep.mdf"

 CategoryInfo          : InvalidOperation: (Amazon.PowerShe...eS3ObjectCmdlet:WriteS3ObjectCmdlet) [Write-S3Object], InvalidOperationException
 FullyQualifiedErrorId : InvalidOperationException,Amazon.PowerShell.Cmdlets.S3.WriteS3ObjectCmdlet
asked a month ago72 views
2 Answers
0
Accepted Answer

It appears that you're encountering a credential issue when trying to use the Write-S3Object cmdlet. Based on the steps you've provided, there are a few things we can check to resolve this issue:

  1. When you set your AWS credentials using Set-AWSCredential, you're storing them with a profile name "myProfileName". However, when you're trying to use Write-S3Object, you're not specifying which profile to use.

  2. To use the credentials you've stored, you need to either set them as the default credentials for your session or specify the profile name when using Write-S3Object.

Here are a couple of ways to resolve this:

Option 1: Set the stored credentials as default for your session: After setting your credentials with Set-AWSCredential, use: Set-AWSCredential -ProfileName myProfileName

Option 2: Specify the profile name when using Write-S3Object: Write-S3Object -BucketName "MyBucketName" -Key "gfi/2013 Jul - Sep.mdf" -File "F:\SQLDB\TO_AWS\2013 Jul - Sep.mdf" -ProfileName myProfileName

Either of these methods should allow the Write-S3Object cmdlet to use the credentials you've stored.

Also, ensure that the IAM user associated with these credentials has the necessary permissions to write objects to the specified S3 bucket. The user should have, at minimum, s3:PutObject permission for the bucket and objects within it.

If you're still encountering issues after trying these solutions, you may want to verify your credentials are correct and that they have the necessary permissions in AWS IAM.
Sources
Using AWS Credentials - AWS Tools for PowerShell
Amazon S3 examples using Tools for PowerShell - AWS SDK Code Examples

profile picture
answered a month ago
profile picture
EXPERT
reviewed a month ago
0

Awesome, thank you! It's tough piecing this altogether. I thought that's what the line Get-EC2Instance -ProfileName MyProfileName was doing.

File is uploading as I write this... thank you!

answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions