Reputation: 179
If I want to upload a file from my "mac" to S3, I can use
import boto3
s3 = boto3.resource('s3', region_name="us-west-1")
s3.meta.client.upload_file('/User/gantao/amz.jpg', 'gantao_created', 'amz.jpg')
But,
Is there any way to upload a file to S3 from EC2 instance (do not use SSH to EC2) ?
Upvotes: 1
Views: 3785
Reputation: 5313
The short answer is "yes."
The longer answer is that, in order to upload a file from an EC2 instance to S3, the deployed EC2 instance has to have the correct permissions to put_object
to S3.
You can either do this by configuring your boto client inside your Python code, or by creating and assigning an IAM role with that permission to your EC2 instance.
The more secure way is to assign the IAM role, since it doesn't require you to have credentials in code or in a file in source control.
To create an IAM role:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html
To add an IAM role to your EC2 instance:
Upvotes: 1