user3731845
user3731845

Reputation: 79

EC2 upload failed to S3

I am trying to upload a file from an EC2 instance to S3 bucket and get this error:

[ec2-user@zzzzzzz parsers]$ aws s3 cp file.txt s3://bucket/output/file.txt

upload failed: ./file.txt to s3://bucket/output/file.txt A client error (InvalidAccessKeyId) occurred when calling the PutObject operation: The AWS Access Key Id you provided does not exist in our records.

I have already configured the aws configure file in EC2 as follows:

[ec2-user@zzzzz parsers]$ aws configure list
Name           Value                 Type           Location
----           -----                 ----           --------
profile        <not set>             None           None
access_key     ****************NTr6  config-file     
secret_key     ****************AFJQ  config-file     
region         us-west-2             config-file    ~/.aws/config

What else should I do to make this work?

Upvotes: 2

Views: 3620

Answers (2)

Sameh Sharaf
Sameh Sharaf

Reputation: 1131

It's recommended to use IAM roles instead of IAM access keys for EC2 instances. By simply creating a IAM role to access S3 and link it to your EC2 instance, you can list, download and upload files from and to your S3 bucket(s) based on the role's policy.

It's more secure and you don't have to configure your aws credentials.

Upvotes: 0

John Rotenstein
John Rotenstein

Reputation: 270224

InvalidAccessKeyId indicates that the Access Key and Secret Key are not valid.

Access Keys (and their corresponding Secret Keys) can be associated to either either:

  • Master (or root) credentials, or
  • An Identity and Access Management (IAM) user

It is recommended that Master credentials not be used on a daily basis. (See IAM Best Practices.)

If your credentials are associated with an IAM user, you can generate a new set of credentials:

  • Go to Identity and Access Management (IAM)
  • Select the User
  • Manage Access Keys
  • Create Access Key

A new Access Key and Secret Key will be displayed. Try using them in CLI configuration.

Up to two sets of Access Keys can be associated with a User at any time.

Upvotes: 3

Related Questions