问题描述
我正在AWS Elastic Beanstalk上运行Django Web应用程序,该应用程序需要特定的可用文件才能运行(实际上, nltk
停用词集)。由于实例来来去去,我将所需的文件夹复制到了由我的弹性beanstalk创建的S3存储桶,并计划使用 awscli
将复制命令添加到我的弹性beanstalk配置文件中。
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 come and go, 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 I can't get it to work.
我的beantalk启动的实例应该具有对S3存储桶的读取权限,因为这是beantalk自动创建的存储桶。因此,beanstalk还创建了一个IAM角色 aws-elasticbeanstalk-ec2-role
,该角色是附加到其启动的每个实例的实例配置文件。该角色包括 AWSElasticBeanstalkWebTier
策略,该策略似乎授予对S3存储桶的读写访问权限:
Instances launched by my beanstalk should have read access to the S3 bucket because this is the bucket created automatically by beanstalk. So 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-*/*"
]
}
]
}
我尝试将以下命令添加到 .ebextensions / my_app.config
:
I tried adding 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/
但是,即使我可以在S3控制台中看到该文件夹,在尝试进行部署时也会遇到以下错误
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
有什么想法吗?
谢谢!
推荐答案
AWS支持人员提供了答案:我的 nltk_data
文件夹中包含子文件夹和文件,因此 aws s3 cp
命令需要-recursive
选项。
AWS Support had the answer: my nltk_data
folder had subfolders and files inside so the aws s3 cp
command needed the --recursive
option.
这篇关于创建实例时如何将文件夹从S3复制到Elastic beantalk实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!