How to copy a folder from S3 to Elastic Beanstalk instance on its creation

0 votes

I'm running a Django web-app on AWS Elastic Beanstalk that needs specific files available to it to run (in fact, an nltk corpus of stopwords). Since instances are created and terminated randomly, I copied the needed folder to the S3 bucket that was created by my elastic beanstalk and planned to add a copy command using awscli to my elastic beanstalk configuration file. But It is not working..

Beanstalk also created an IAM role aws-elasticbeanstalk-ec2-role which is an instance profile that is attached to every instance it launches. This role includes the AWSElasticBeanstalkWebTier policy which seems to grant both read and write access to the S3 bucket:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "BucketAccess",
      "Action": [
        "s3:Get*",
        "s3:List*",
        "s3:PutObject"
      ],
      "Effect": "Allow",
      "Resource": [
        "arn:aws:s3:::elasticbeanstalk-*",
        "arn:aws:s3:::elasticbeanstalk-*/*"
      ]
    }
  ]
} 

I added the following command to .ebextensions/my_app.config:

commands: 01_copy_nltk_data: command: aws s3 cp s3://<my_bucket>/nltk_data /usr/local/share/

But I get the following error when I try to deploy even though I can see the folder in my S3 console

Command failed on instance. Return code: 1 Output: An error occurred (404) when calling the HeadObject operation: Key "nltk_data" does not exist

Any ideas?

Aug 24, 2018 in AWS by datageek
• 2,540 points
4,572 views

1 answer to this question.

0 votes

I had encountered similar problem. But i found this solution posted by AWS support. My  folder had subfolders and files inside so asw s3 cp command needed --recursive option.

Try it out. It will work.

answered Aug 24, 2018 by Archana
• 4,170 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer
0 votes
0 answers

How can I migrate Elastic beanstalk env from one region to another on AWS?

I need help! How can i migrate ...READ MORE

Sep 18, 2020 in AWS by anonymous
• 19,610 points
1,757 views
0 votes
1 answer

How can i copy tables from one database to other on AWS?

You can use AWS Data pipeline to ...READ MORE

answered Jul 5, 2018 in AWS by Priyaj
• 58,020 points
4,787 views
0 votes
1 answer

How to copy .csv file from Amazon S3 bucket?

Boto3 is the library to use for ...READ MORE

answered Jul 6, 2018 in AWS by Priyaj
• 58,020 points
2,097 views
0 votes
1 answer

AWS Elastic Beanstalk - How to increase instance disk capacity?

The 8 GB diskthat you are seeing ...READ MORE

answered Sep 3, 2018 in AWS by anonymous
3,984 views
0 votes
1 answer

How to download a file from EC2 instance to local computer?

You need to specify your download location. ...READ MORE

answered Oct 10, 2018 in AWS by Archana
• 4,170 points
8,640 views
0 votes
2 answers

How to access files in S3 bucket from R?

You can take a look at the ...READ MORE

answered Aug 10, 2018 in AWS by Deepthi
• 300 points
6,617 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP