1

i've a problem with my Amazon Elastic Beanstalk and Amazon S3 setup.

From the EB instance i want to load a file with node (fs.readFileSync), i tried a ton of configurations - but non of them worked, so you're my last hope.

Here is my .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

And here the bucket policy from the 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/*"
            ]
        }
    ]
}

Now when i query the file with node:

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

The log's in EB says:

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)

Important, the aws-elasticbeanstalk-ec2-role role has this policies:

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

This is a copy from the same question on Stack-Overflow, i think this is a better page to ask this question..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.