使用Elastic Beanstalk时将文件从S3复制到我的代码库 [英] Copying a file from S3 into my codebase when using Elastic Beanstalk

查看:40
本文介绍了使用Elastic Beanstalk时将文件从S3复制到我的代码库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本:

Parameters:
  bucket:
    Type: CommaDelimitedList
    Description: "Name of the Amazon S3 bucket that contains your file"
    Default: "my-bucket"
  fileuri:
    Type: String
    Description: "Path to the file in S3"
    Default: "https://my-bucket.s3.eu-west-2.amazonaws.com/oauth-private.key"
  authrole:
    Type: String
    Description: "Role with permissions to download the file from Amazon S3"
    Default: "aws-elasticbeanstalk-ec2-role"

files:
  /var/app/current/storage/oauth-private.key:
    mode: "000600"
    owner: webapp
    group: webapp
    source: { "Ref" : "fileuri" }
    authentication: S3AccessCred

Resources:
  AWSEBAutoScalingGroup:
    Type: "AWS::AutoScaling::AutoScalingGroup"
    Metadata:
      AWS::CloudFormation::Authentication:
        S3AccessCred:
          type: "S3"
          roleName: { "Ref" : "authrole" }
          buckets: { "Ref" : "bucket" }

我遇到的问题是,在部署此文件时,该文件不在/var/app/current/storage 目录中.

The issue that I am having is that when this is being deployed, the file aren't present in the /var/app/current/storage directory.

我认为该脚本可能运行得太早,而 current 目录尚未准备好,所以我尝试了 ondeck 目录,但该命令也无法正常工作.

I thought that maybe this script was running too soon and the current directory wasn't ready yet, so I tried the ondeck directory and this also doesn't work.

如果我将路径更改为除我的代码库目录之外的其他任何路径,则该文件将从S3复制.

If I change the path to anywhere other than my codebase directory it works, the file is copied from S3.

有什么想法吗?谢谢.

推荐答案

在设置Web应用程序之前,必须先处理文件"键下的指令.您需要将文件下载到tmp文件,然后使用 container_command 将其传输到当前目录中的应用程序.

Directives under the "files" key are processed before your web application is set up. You will need to download the file to a tmp file, and then use a container_command to transfer it to your app in the current directory.

AWS文档在附近提到按键处理的顺序排在最前面.在设置应用程序和Web服务器之前,先运行 files 键,然后再运行 commands commands .但是, container_commands 部分指出,它们用于执行影响您的应用程序源代码的命令".

This AWS doc mentions near the top the order in which keys are processed. The files key is processed before commands, and commands are run before the application and web server are set up. However, the container_commands section notes that they are used "to execute commands that affect your application source code".

因此,您应该将脚本修改为以下内容:

So you should modify your script to something like this:

Parameters: ...
Resources: ...

files:
  "/tmp/oauth-private.key":
    mode: "000600"
    owner: webapp
    group: webapp
    source: { "Ref" : "fileuri" }
    authentication: S3AccessCred

container_commands:
  file_transfer_1:
    command: "mkdir -p storage"
  file_transfer_2:
    command: "mv /tmp/oauth-private.key storage"

这篇关于使用Elastic Beanstalk时将文件从S3复制到我的代码库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆