使用.ebextensions配置从s3中提取的文件无法从webapp访问

时间:2017-09-19 15:11:08

标签: python amazon-s3 amazon-ec2 elastic-beanstalk amazon-elastic-beanstalk

我试图将一个私钥从S3拉入我的弹性beanstalk应用程序而不将其添加为环境变量(听说这不安全)。我可以将这个文件从S3拉到我的实例上(通过SSH验证到实例并检查文件)。但是,我无法从我的应用程序访问此文件。我正在运行Flask python应用程序。当我尝试从我的python应用程序访问该文件时,出现FileNotFoundError: [Errno 2] No such file or directory: '/etc/server.key'错误。

(1)这是多么敏感的秘密应该处理? (2)知道为什么我可以在SSH时检查文件,但不能从我的应用程序检查文件?

我有.ebextensions/privatekey.config这样:

Resources:
  AWSEBAutoScalingGroup:
    Metadata:
      AWS::CloudFormation::Authentication:
        S3Auth:
          type: "s3"
          buckets: ["elasticbeanstalk-us-west-2-111111111111"]
          roleName: 
            "Fn::GetOptionSetting": 
              Namespace: "aws:autoscaling:launchconfiguration"
              OptionName: "IamInstanceProfile"
              DefaultValue: "aws-elasticbeanstalk-ec2-role"
files:
  # Private key
  /etc/server.key:
    mode: "000755"
    owner: root
    group: root
    authentication: "S3Auth"
    source: https://s3-us-west-2.amazonaws.com/elasticbeanstalk-us-west-2-111111111111/mycoolapp/server.key

我只是想做一个简单的事情:

with open("/etc/server.key") as file:  
    data = file.read()

在python中。

0 个答案:

没有答案