我试图从私人s3桶检索一些文件到文件系统位置elastic beanstalk ec2实例,但没有成功。
我创build了一个名为dev-config的桶,其中包含一个名为local.properties的文件。
我已经创build了一个IAM策略
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "s3:*", "Resource": [ "arn:aws:s3:::dev-config", "arn:aws:s3:::dev-config/*" ] } ] }
并将该策略与IAMangular色相关联,该angular色又与EC2实例相关联。 我已经确认,我可以使用aws-cli从s3存储桶获取文件,而不提供任何其他凭据。 即aws s3 ls s3://dev-config/local.properties
我的项目中添加了以下文件:
.ebextensions / 01_files.config
"/usr/share/tomcat7/lib/local.properties" : mode: "000777" owner: ec2-user group: ec2-user source: http://s3.amazonaws.com/dev-config/local.properties
我也尝试了一些源代码的变种
source: http://dev-config.s3.amazonaws.com/dev-config/local.properties source: http://dev-config.s3.amazonaws.com/local.properties source: s3://dev-config/local.properties
而且我也尝试添加一个authentication属性没有成功(似乎没有可能的身份validation文件)。 authentication:S3Access
迄今为止,这些方法都没有奏效。
在某些情况下,我在日志中获取拒绝访问的消息:
<?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied</Message> <RequestId>blahblah</RequestId> <HostId>blahblah</HostId> </Error>
在其他情况下,我在local.properties文件本身中有错误消息。PermanentRedirect您尝试访问的存储区必须使用指定的端点进行寻址。 请将所有未来请求发送到此端点。 dev-config dev-config.s3.amazonaws.com
blahlblah blahlblah
设法得到这个工作?
看看这个答案后使用弹性beanstalkconfiguration文件中的文件使用环境属性我将下面的部分添加到.ebextensions/01_files.config
Resources: AWSEBAutoScalingGroup: Metadata: AWS::CloudFormation::Authentication: S3Access: type: S3 roleName: aws-elasticbeanstalk-ec2-role buckets: dev-config
并更新了s3 url以在主机中包含存储桶名称,所以最终的文件如下所示:
"/usr/share/tomcat7/lib/local.properties" : mode: "000777" owner: ec2-user group: ec2-user source: https://dev-config.s3.amazonaws.com/local.properties Resources: AWSEBAutoScalingGroup: Metadata: AWS::CloudFormation::Authentication: S3Access: type: S3 roleName: aws-elasticbeanstalk-ec2-role buckets: dev-config
这使得弹性beanstalk ec2实例可以使用与其关联的IAMangular色来访问包含文件的s3存储桶。
PS:要使此configurationaws-elasticbeanstalk-ec2-role ,请确保已授予对aws-elasticbeanstalk-ec2-role主体的有问题的S3存储桶的访问权限。 您可以从IAM控制台获取ARN。
试试这个IAM。 这个对我有用。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject" ], "Resource": [ "arn:aws:s3:::dev-config", "arn:aws:s3:::dev-config/*" ] } ] }
如果你需要读/写/删除权限,你需要这样的东西:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:DeleteObject", "s3:GetObject", "s3:PutObject" ], "Resource": [ "arn:aws:s3:::dev-config", "arn:aws:s3:::dev-config/*" ] } ] }
问候。