Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grant S3 access to Elastic Beanstalk instances

I'm trying to provision my EC2 instances in Elastic Beanstalk with some ssh keys from a private S3 bucket. Here's a snippet of my .ebextensions/.config:

files:
  "/root/.ssh/id_rsa" :
    mode: "000400"
    ownder: root
    group: root
    source: https://s3-us-west-2.amazonaws.com/<bucket>/<app>_id_rsa

Unfortunately, I'm getting a 403 response from S3. Is there a way to grant access to the EC2 instances using a Security Group? I can't grant each instance access individually as I won't know their IPs before they are scaled. Is there some other way to grant just this Elastic Beanstalk app access? I'm having trouble coming up with a good S3 Bucket Policy...

like image 497
jamstooks Avatar asked Feb 08 '14 23:02

jamstooks


People also ask

Can S3 be used with EC2 instances?

Amazon EC2 uses Amazon S3 for storing Amazon Machine Images (AMIs). You use AMIs for launching EC2 instances. In case of instance failure, you can use the stored AMI to immediately launch another instance, thereby allowing for fast recovery and business continuity.


2 Answers

first click on the tab below

enter image description here

then click on the added role

enter image description here

and add AmazonS3FullAccess access policy

enter image description here

like image 150
Ahmet Şimşek Avatar answered Sep 24 '22 19:09

Ahmet Şimşek


In my case I tried creating a new EC2 role that would include access policy to S3, but could not get it working, as it seems by default this role does not get attached to ec2 instances? Played around with VPC S3 bucket roles, but that only messed up bucket and locked me out. The proper solution was to add the S3 access policy to already existing ElasticBeanstalk role:

aws-elasticbeanstalk-ec2-role

that @chaseadamsio and @tom mentioned, thank you for that.

like image 37
Maksim Luzik Avatar answered Sep 22 '22 19:09

Maksim Luzik