dif*_*ffa 5 amazon-s3 amazon-ec2 amazon-iam elastic-beanstalk
我正在尝试将一些文件从私有 s3 存储桶检索到文件系统位置弹性 beantalk ec2 实例,但没有成功。
我创建了一个名为的存储桶,dev-config
其中包含一个名为local.properties
.
我创建了一个 IAM 策略
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::dev-config",
"arn:aws:s3:::dev-config/*"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
并将该策略与 IAM 角色相关联,该角色又与 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
Run Code Online (Sandbox Code Playgroud)
我还尝试了源网址的一些变体
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
Run Code Online (Sandbox Code Playgroud)
而且我也尝试添加一个authentication
属性但没有成功(似乎没有关于可能的身份验证值的文档)。身份验证:S3Access
到目前为止,这些方法都没有奏效。
在某些情况下,我会在日志中收到拒绝访问的消息:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message>
<RequestId>blahblah</RequestId>
<HostId>blahblah</HostId>
</Error>
Run Code Online (Sandbox Code Playgroud)
在其他情况下,我在 local.properties 文件本身中有错误消息
PermanentRedirect
您尝试访问的存储桶必须使用指定的端点进行寻址。请将所有未来的请求发送到此端点。dev-config dev-config.s3.amazonaws.com
blahlblah blahlblah
已经设法让这个工作?
在查看了使用环境属性与弹性 beanstalk 配置文件中的文件的答案后,我将以下部分添加到.ebextensions/01_files.config
Resources:
AWSEBAutoScalingGroup:
Metadata:
AWS::CloudFormation::Authentication:
S3Access:
type: S3
roleName: aws-elasticbeanstalk-ec2-role
buckets: dev-config
Run Code Online (Sandbox Code Playgroud)
并更新了 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
Run Code Online (Sandbox Code Playgroud)
这使得 Elastic beanstalk ec2 实例能够使用与其关联的 IAM 角色来访问包含文件的 s3 存储桶。
PS:要使此配置生效,请确保您已向主体授予对相关 S3 存储桶的访问权限aws-elasticbeanstalk-ec2-role
。您可以从 IAM 控制台获取 ARN。
归档时间: |
|
查看次数: |
5685 次 |
最近记录: |