在 AWS ebextensions 中执行命令
Posted
技术标签:
【中文标题】在 AWS ebextensions 中执行命令【英文标题】:executing commands in AWS ebextensions 【发布时间】:2015-09-27 18:18:10 【问题描述】:尝试在 aws elasticbeanstalk 中上传我的实例时收到以下错误:
The configuration file .ebextensions/setup.config in application version t5 contains invalid YAML or JSON.
YAML exception: while scanning a quoted scalar in "<reader>", line 3, column 18: command:
"aws s3 cp s3:elasticbeanstalk-u ... ^ found unexpected end of stream in "<reader>",
line 5, column 1: ^ , JSON exception: Unexpected character (c) at position 0.. Update the configuration file.
以下是setup.config
文件中包含的内容:
container_commands:
01_setup_apache:
command: "aws s3 cp s3:elasticbeanstalk-us-west-2-273610000489/enable_mod_rewrite.conf /etc/httpd/co
我正在使用 AWS 弹性 beanstalk,由于我无法将 httdp conf
文件修改为 AllowOverride All
以便使用重写规则清理我的 URL,因此建议我使用 ebextensions:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
更新:
我认为运行的问题是这样的:
RewriteEngine On
位于 htaccess 中。几乎就像它不能接受 rewritenegine 被打开一样。
更新2:
在/var/log/httpd/access_log
在/var/log/eb-activity.log
:
Command CMD-TailLogs succeeded.
[2015-07-10T10:25:09.784Z] INFO [25589] - [CMD-TailLogs] : Starting activity...
[2015-07-10T10:25:10.206Z] INFO [25589] - [CMD-TailLogs/AddonsBefore] : Starting activity...
[2015-07-10T10:25:10.207Z] INFO [25589] - [CMD-TailLogs/AddonsBefore] : Completed activity.
[2015-07-10T10:25:10.207Z] INFO [25589] - [CMD-TailLogs/TailLogs] : Starting activity...
[2015-07-10T10:25:10.207Z] INFO [25589] - [CMD-TailLogs/TailLogs/TailLogs] : Starting activity...
在/var/log/eb-commandprocessor.log
[2015-07-10T10:37:19.644Z] DEBUG [25873] : Checking if the command processor should execute...
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Checking whether the command is applicable to instance (i-80bbbd77)..
[2015-07-10T10:37:19.645Z] INFO [25873] : Command is applicable to this instance (i-80bbbd77)..
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Checking if the received command stage is valid..
[2015-07-10T10:37:19.645Z] INFO [25873] : No stage_num in command. Valid stage..
[2015-07-10T10:37:19.645Z] INFO [25873] : Command processor should execute command.
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Storing current stage..
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Stage_num does not exist. Not saving null stage. Returning..
[2015-07-10T10:37:19.646Z] INFO [25873] : Executing command: CMD-TailLogs...
[2015-07-10T10:37:19.646Z] DEBUG [25873] : Reading config file: /etc/elasticbeanstalk/.aws-eb-stack.properties
[2015-07-10T10:37:19.647Z] DEBUG [25873] : Refreshing metadata..
[2015-07-10T10:37:20.061Z] DEBUG [25873] : Refreshed environment metadata.
[2015-07-10T10:37:20.061Z] DEBUG [25873] : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_ContainerConfigFileContent||commands..
[2015-07-10T10:37:20.062Z] DEBUG [25873] : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_API||_Commands..
[2015-07-10T10:37:20.064Z] INFO [25873] : Found enabled addons: ["logpublish"].
[2015-07-10T10:37:20.066Z] INFO [25873] : Updating Command definition of addon logpublish.
[2015-07-10T10:37:20.066Z] DEBUG [25873] : Loaded definition of Command CMD-TailLogs.
[2015-07-10T10:37:20.066Z] INFO [25873] : Executing command CMD-TailLogs activities...
[2015-07-10T10:37:20.066Z] DEBUG [25873] : Setting environment variables..
[2015-07-10T10:37:20.066Z] INFO [25873] : Running AddonsBefore for command CMD-TailLogs...
[2015-07-10T10:37:20.067Z] DEBUG [25873] : Running stages of Command CMD-TailLogs from stage 0 to stage 0...
[2015-07-10T10:37:20.067Z] INFO [25873] : Running stage 0 of command CMD-TailLogs...
[2015-07-10T10:37:20.067Z] DEBUG [25873] : Loaded 1 actions for stage 0.
[2015-07-10T10:37:20.067Z] INFO [25873] : Running 1 of 1 actions: TailLogs...
更新 3:
【问题讨论】:
你给的setup.config
被切断了。
【参考方案1】:
在将 .ebextensions 提交到 Elastic Beanstalk 之前,请务必检查它们。我用来检查文件的资源http://www.yamllint.com/
如果您尝试修改 Apache 配置,那么我建议您在 ebextensions 中使用“文件”。 read more...
我相信您正在努力实现以下目标:
files:
"/etc/httpd/conf.d/enable_mod_rewrite.conf":
mode: "644"
owner: root
group: root
content: |
AllowOverride All
【讨论】:
感谢您的澄清和编辑。当使用 setup.config 中添加的建议命令上传新实例时,实例的运行状况变为红色,如我的初始帖子下的图像更新所示 检查您的错误日志 - 那里可能有用。 感谢您的建议。我在我的初始帖子下更新了更新 2。特别是在 /var/log/httpd/error_log 下什么都没有写 在您的 EBStalk 配置中;在网络层,负载平衡下,您的 EC2 实例运行状况检查是什么?如果你有一个把它拿出来再试一次。 嗨。 EC2 实例健康检查是什么意思?我用 ec2 health 中的值更新了我的初始帖子。它仍然是红色的,使用这个配置文件 + 在 htacess 中重写给出红色,没有这个配置文件它的绿色,但显然 htaccess 不起作用【参考方案2】:根据乔治的回答,这对我有用。可以帮助遇到同样故障的其他人:
files:
"/etc/httpd/conf.d/enable_mod_rewrite.conf":
mode: "644"
owner: root
group: root
content: |
<Directory /opt/python/current/app/>
AllowOverride All
</Directory>
这是使用 django 应用程序,因此您需要将 .htaccess 文件放在主项目目录中。如果您放置在静态文件夹中,则在登录弹出窗口上按取消后,只有未经授权的用户仍然可以看到/单击某些内容。
【讨论】:
以上是关于在 AWS ebextensions 中执行命令的主要内容,如果未能解决你的问题,请参考以下文章
AWS ElasticBeanstalk .ebextensions 未执行
使用 AWS ebextensions,按照他们的文档传递一组命令的正确方法是啥?