首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在.ebextensions文件夹中运行弹性豆柄命令行命令?

如何在.ebextensions文件夹中运行弹性豆柄命令行命令?
EN

Stack Overflow用户
提问于 2021-12-08 21:32:08
回答 1查看 482关注 0票数 1

我有几个命令,我需要在一个新的弹性豆柄实例启动时运行。如何构造.config文件,以便在新实例的启动时运行这些命令。这些是我需要做的检查:

代码语言:javascript
复制
INSTANCE_ID=$(ec2-metadata -i)
words=( $INSTANCE_ID )
EC2_ID="${words[1]}"

aws ec2 associate-address --instance-id $EC2_ID --allocation-id eipalloc-16c1ecdcesrxx

如何在名为setup.config.ebextensions文件夹中运行此文件?我想像这样的事情:

代码语言:javascript
复制
container_commands:
  00bootup:
    command: "INSTANCE_ID=$(ec2-metadata -i)"
    command: "words=( $INSTANCE_ID )"
    command: "EC2_ID="${words[1]}""
    command: "aws ec2 associate-address --instance-id $EC2_ID --allocation-id eipalloc-16c1ecdcesrxx"

然而,这并没有像预期的那样设置弹性IP。

更新:我试过这样做:

代码语言:javascript
复制
--- 
container_commands: 
  00setup: 
    command: |-
        export AWS_DEFAULT_REGION=US-EAST-1    
        export AWS_ACCESS_KEY_ID=MY_KEY
        export AWS_SECRET_ACCESS_KEY=MY_SECRET_KEY
        INSTANCE_ID=$(ec2-metadata -i)
        words=( $INSTANCE_ID )
        EC2_ID="${words[1]}"
        aws ec2 associate-address --instance-id $EC2_ID --allocation-id eipalloc-06cXXXXXXXXXX

当我部署环境时,它就失败了。它不会部署,但是如果我不使用.config文件,那么它将成功部署。这是日志:

代码语言:javascript
复制
2021/12/09 11:55:01.043643 [INFO] Executing instruction: configure X-Ray
2021/12/09 11:55:01.043652 [INFO] X-Ray is not enabled.
2021/12/09 11:55:01.043657 [INFO] Executing instruction: configure proxy Nginx
2021/12/09 11:55:01.070732 [INFO] Executing instruction: configure healthd specific proxy conf
2021/12/09 11:55:01.073824 [INFO] Running command /bin/sh -c systemctl show -p PartOf healthd.service
2021/12/09 11:55:01.400439 [INFO] Running command /bin/sh -c systemctl daemon-reload
2021/12/09 11:55:02.065983 [INFO] Running command /bin/sh -c systemctl reset-failed
2021/12/09 11:55:02.070668 [INFO] Running command /bin/sh -c systemctl is-enabled aws-eb.target
2021/12/09 11:55:02.090250 [INFO] Running command /bin/sh -c systemctl enable aws-eb.target
2021/12/09 11:55:02.166046 [INFO] Running command /bin/sh -c systemctl start aws-eb.target
2021/12/09 11:55:02.184403 [INFO] Running command /bin/sh -c systemctl enable healthd.service
2021/12/09 11:55:02.258453 [INFO] Running command /bin/sh -c systemctl show -p PartOf healthd.service
2021/12/09 11:55:02.270566 [INFO] Running command /bin/sh -c systemctl is-active healthd.service
2021/12/09 11:55:02.274378 [INFO] Running command /bin/sh -c systemctl start healthd.service
2021/12/09 11:55:02.320050 [INFO] Copying file /opt/elasticbeanstalk/config/private/healthd/healthd_logformat.conf to /var/proxy/staging/nginx/conf.d/healthd_logformat.conf
2021/12/09 11:55:02.322053 [INFO] Copying file /opt/elasticbeanstalk/config/private/healthd/healthd_nginx.conf to /var/proxy/staging/nginx/conf.d/elasticbeanstalk/healthd.conf
2021/12/09 11:55:02.325036 [INFO] Executing instruction: configure log streaming
2021/12/09 11:55:02.325048 [INFO] log streaming is not enabled
2021/12/09 11:55:02.325052 [INFO] disable log stream
2021/12/09 11:55:02.325066 [INFO] Running command /bin/sh -c systemctl show -p PartOf amazon-cloudwatch-agent.service
2021/12/09 11:55:02.340721 [INFO] Running command /bin/sh -c systemctl stop amazon-cloudwatch-agent.service
2021/12/09 11:55:02.345794 [INFO] Executing instruction: GetToggleForceRotate
2021/12/09 11:55:02.345807 [INFO] Checking if logs need forced rotation
2021/12/09 11:55:02.345844 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-1:796071762232:stack/awseb-e-8eps8ub4a3-stack/1f9bcf70-58e6-11ec-8466-127df4d38a9f -r AWSEBAutoScalingGroup --region us-east-1
2021/12/09 11:55:04.975344 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-1:796071762232:stack/awseb-e-8eps8ub4a3-stack/1f9bcf70-58e6-11ec-8466-127df4d38a9f -r AWSEBBeanstalkMetadata --region us-east-1
2021/12/09 11:55:05.364102 [INFO] Procfile not found. Generating default rsyslog config
2021/12/09 11:55:05.366813 [INFO] Running command /bin/sh -c systemctl restart rsyslog.service
2021/12/09 11:55:06.345757 [INFO] Executing instruction: Configure Docker Logging
2021/12/09 11:55:06.365153 [INFO] Executing instruction: PostBuildEbExtension
2021/12/09 11:55:06.365179 [INFO] Starting executing the config set Infra-EmbeddedPostBuild.
2021/12/09 11:55:06.365193 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-init -s arn:aws:cloudformation:us-east-1:796071762232:stack/awseb-e-8eps8ub4a3-stack/1f9bcf70-58e6-11ec-8466-127df4d38a9f -r AWSEBAutoScalingGroup --region us-east-1 --configsets Infra-EmbeddedPostBuild
2021/12/09 11:55:20.596390 [ERROR] An error occurred during execution of command [app-deploy] - [PostBuildEbExtension]. Stop running the command. Error: Container commands build failed. Please refer to /var/log/cfn-init.log for more details. 

2021/12/09 11:55:20.596410 [INFO] Executing cleanup logic
2021/12/09 11:55:20.596519 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1639050920,"severity":"ERROR"}]}]}

2021/12/09 11:55:20.597712 [INFO] Platform Engine finished execution on command: app-deploy

2021/12/09 11:56:44.993323 [INFO] Starting...
2021/12/09 11:56:44.993370 [INFO] Starting EBPlatform-PlatformEngine
2021/12/09 11:56:44.994105 [INFO] reading event message file
2021/12/09 11:56:45.002909 [INFO] no eb envtier info file found, skip loading env tier info.
2021/12/09 11:56:45.002987 [INFO] Engine received EB command cfn-hup-exec

2021/12/09 11:56:45.109117 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-1:796071762232:stack/awseb-e-8eps8ub4a3-stack/1f9bcf70-58e6-11ec-8466-127df4d38a9f -r AWSEBAutoScalingGroup --region us-east-1
2021/12/09 11:56:45.596582 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-1:796071762232:stack/awseb-e-8eps8ub4a3-stack/1f9bcf70-58e6-11ec-8466-127df4d38a9f -r AWSEBBeanstalkMetadata --region us-east-1
2021/12/09 11:56:45.956533 [INFO] checking whether command tail-log is applicable to this instance...
2021/12/09 11:56:45.956550 [INFO] this command is applicable to the instance, thus instance should execute command
2021/12/09 11:56:45.956555 [INFO] Engine command: (tail-log)

2021/12/09 11:56:45.957863 [INFO] Executing instruction: GetTailLogs
2021/12/09 11:56:45.957872 [INFO] Tail Logs...
2021/12/09 11:56:45.963685 [INFO] Running command /bin/sh -c tail -n 100 /var/log/eb-engine.log

我的setup.config文件的格式有什么问题。我把它放在.ebextensions文件夹里。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-09 00:03:21

要将这些多个命令作为一个运行,可以执行以下操作:

代码语言:javascript
复制
container_commands:
  00bootup:
    command: |
       INSTANCE_ID=$(ec2-metadata -i)
       words=( $INSTANCE_ID )
       EC2_ID="${words[1]}"
       aws ec2 associate-address --instance-id $EC2_ID --allocation-id eipalloc-16c1ecdcesrxx
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70281968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档