1. Create a separate AWS user
I recommend creating a separated user for uploading to your S3 bucket.
- Select the AWS Service
IAM
->Users
->Add user
User name
: s3_userPermission options
: Attach policies directly- Select
AmazonS3FullAccess
- Click
Next
->Create user
2. Configure AWS user
We need to create an access_key
and secret_key
in order to use our s3_user
within the aws
command.
- Select your
s3_user
and go toSecurity credentials
- Under Access keys click
Create access key
- Choose
Application running on an AWS compute service
- Click
Create access key
- Store the
Access key
andSecret access key
3. Configure AWS CLI
aws configure --profile s3_user
AWS Access Key ID [None]: <your_access_key>
AWS Secret Access Key [None]: <your_secret_access_key>
Default region name [None]: eu-central-1
Default output format [None]: json
4. Upload file to S3
Now you can upload a file to your S3 bucket using your new profile
aws s3 cp /opt/test.txt s3://mybucketname/test.txt --profile s3_user
5. Download file from S3
aws s3 cp s3://mybucketname/test.txt /opt/test.txt --profile s3_user
6. Conclusion
In this article we have learned how to configure an user
and the aws cli
to conveniently upload and download files from S3
to your EC2 instance
.