Amazon Elastic Beanstalk com acesso a arquivos para o Amazon S3

1

Eu tenho um problema com minha configuração do Amazon Elastic Beanstalk e Amazon S3 .

A partir da instância do EB eu quero carregar um arquivo com o nó ( fs.readFileSync ), eu tentei uma tonelada de configurações - mas nenhum deles funcionou, então você é minha última esperança.

Aqui está meu .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

E aqui a política de bucket do 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/*"
            ]
        }
    ]
}

Agora, quando eu consultar o arquivo com o nó:

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

O log no EB diz:

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)

Importante, a função aws-elasticbeanstalk-ec2-role tem estas políticas:

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

Esta é uma cópia da mesma pergunta em Stack- Estouro , acho que esta é uma página melhor para fazer essa pergunta ..

    
por Michael J. Zoidl 07.10.2016 / 11:38

0 respostas