Amazon Elastic Beanstalk具有对Amazon S3的文件访问权限

我的Amazon Elastic BeanstalkAmazon S3安装程序有问题。

从EB实例我想加载一个文件与节点( fs.readFileSync ),我试了fs.readFileSync的configuration – 但他们没有工作,所以你是我最后的希望。

这是我的.ebextensions/key.config

 Resources: AWSEBAutoScalingGroup: Metadata: AWS::CloudFormation::Authentication: S3Auth: type: S3 buckets: mybucket roleName: aws-elasticbeanstalk-ec2-role files: /var/app/dummy.txt: authentication: S3Auth source: https://s3.eu-central-1.amazonaws.com/mybucket/dummy.txt 

这里从S3的桶政策

 { "Version": "2008-10-17", "Id": "BeanstalkS3", "Statement": [ { "Sid": "e-123-123", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123123:role/aws-elasticbeanstalk-ec2-role" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::mybucket/resources/environments/logs/*" }, { "Sid": "e-123-123", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123123:role/aws-elasticbeanstalk-ec2-role" }, "Action": [ "s3:ListBucket", "s3:ListBucketVersions", "s3:GetObject", "s3:GetObjectVersion" ], "Resource": [ "arn:aws:s3:::mybucket", "arn:aws:s3:::mybucket/*" ] } ] } 

现在,当我查询与节点的文件:

 fs.readFileSync('/var/app/dummy.txt') 

EB中的日志说:

 Error: ENOENT: no such file or directory, open '/var/app/dummy.txt' at Error (native) at Object.fs.openSync (fs.js:549:18) at Object.fs.readFileSync (fs.js:397:15) at /var/app/current/server.js:68:25 at Layer.handle [as handle_request] (/var/app/current/node_modules/express/lib/router/layer.js:95:5) at next (/var/app/current/node_modules/express/lib/router/route.js:131:13) at Route.dispatch (/var/app/current/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/var/app/current/node_modules/express/lib/router/layer.js:95:5) at /var/app/current/node_modules/express/lib/router/index.js:277:22 at Function.process_params (/var/app/current/node_modules/express/lib/router/index.js:330:12) at next (/var/app/current/node_modules/express/lib/router/index.js:271:10) at /var/app/current/server.js:52:3 at Layer.handle [as handle_request] (/var/app/current/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/var/app/current/node_modules/express/lib/router/index.js:312:13) at /var/app/current/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/var/app/current/node_modules/express/lib/router/index.js:330:12) 

重要的是, aws-elasticbeanstalk-ec2-roleangular色具有以下策略:

  • AmazonS3FullAccess
  • AmazonDynamoDBFullAccess
  • AWSElasticBeanstalkWebTier
  • AmazonS3ReadOnlyAccess
  • AWSElasticBeanstalkMulticontainerDocker
  • AWSElasticBeanstalkWorkerTier
  • AWSCloudFormationReadOnlyAccess

这是从Stack-Overflow相同的问题的副本,我认为这是一个更好的页面来问这个问题..