场景:
命令未被执行.
.ebextensions应该放在Java应用程序中的哪个位置?
java war amazon-web-services amazon-elastic-beanstalk ebextensions
语境
我正在使用 Elastic Beanstalk 部署一个非常简单的测试应用程序。我有几个要使用 apt 安装的软件包。我01_installations.sh在.platform/hooks/prebuild目录中包含了一个安装脚本。当我压缩我的应用程序并部署到 Elastic Beanstalk 时,日志确认预构建脚本运行,但它没有权限。
2020/08/12 21:03:46.674234 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2020/08/12 21:03:46.674256 [INFO] Executing platform hooks in .platform/hooks/prebuild/
2020/08/12 21:03:46.674296 [INFO] Following platform hooks will be executed in order: [01_installations.sh]
2020/08/12 21:03:46.674302 [INFO] Running platform hook: .platform/hooks/prebuild/01_installations.sh
2020/08/12 21:03:46.674482 [ERROR] An error occurred during execution of command [app-deploy] - [RunAppDeployPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/01_installations.sh failed with error fork/exec .platform/hooks/prebuild/01_installations.sh: permission denied
Run Code Online (Sandbox Code Playgroud)
题
我的理解是权限被拒绝,因为我没有添加chmod +x以使 .sh …
我在AWS Elastic Beanstalk的软件配置选项卡中定义了一个名为MY_ENVIRONMENT_VARIABLE的环境变量.
现在我想在.ebextensions配置文件的"files:"部分中使用此环境变量.
Resources:
AWSEBAutoScalingGroup:
Metadata:
AWS::CloudFormation::Authentication:
S3Auth:
type: S3
buckets: arn:aws:s3:::SomeS3Bucket
roleName: aws-elasticbeanstalk-ec2-role
files:
"/tmp/application.properties" :
mode: "000644"
owner: root
group: root
source: { "Ref" : "MY_ENVIRONMENT_VARIABLE" }
authentication: S3Auth
container_commands:
01-apply-configuration:
command: mv /tmp/application.properties .
Run Code Online (Sandbox Code Playgroud)
似乎可以在"container_commands:"部分引用环境变量(通过使用bash脚本),但我找不到任何可以在"files:"部分内引用的引用.
有没有人有一个如何在"files:"部分中使用环境变量的例子?
amazon-s3 amazon-web-services amazon-elastic-beanstalk ebextensions
我有一个spring-boot应用程序,我需要指定石墨服务器和端口(发送指标).要做到这一点,我必须安装和配置statsd.我这样做是使用该ebextensions文件.
commands:
01_nodejs_install:
command: sudo yum -y install nodejs npm --enablerepo=epel
ignoreErrors: true
02_mkdir_statsd:
command: mkdir /home/ec2-user/statsd
ignoreErrors: true
03_fetch_statsd:
command: git clone https://github.com/etsy/statsd.git /home/ec2-user/statsd
ignoreErrors: true
04_change_example_config:
command: "cat exampleConfig.js | sed 's/2003/<graphite-port>/g' | sed 's/graphite.example.com/<my-graphite-server>/g' > config.js"
cwd: /home/ec2-user/statsd
05_run_statsd:
command: setsid node stats.js config.js >/dev/null 2>&1 < /dev/null &
cwd: /home/ec2-user/statsd
Run Code Online (Sandbox Code Playgroud)
这种配置的问题是我可以在这里为所有环境仅指定1个石墨服务器.
所以我决定将命令04和05移入container_commands.我想定义叫做环境变量的ENV_NAME 使用魔豆控制台/ UI,并将其设置为dev,qa或prod根据环境.然后我可以使用test选项container_commands仅基于此特定环境运行04和05命令ENV_NAME.
所以我的问题是 - …
java environment-variables amazon-web-services amazon-elastic-beanstalk ebextensions
我们正在尝试在s3中存储特定于环境的应用程序配置文件.这些文件存储在不同的子目录中,这些子目录以环境命名,并且还将环境作为文件名的一部分.
例子是
dev/application-dev.properties
stg/application-stg.properties
prd/application-prd.properties
Run Code Online (Sandbox Code Playgroud)
Elastic Beanstalk环境名为dev,stg,prd,另外我还有一个名为ENVIRONMENT的Elastic Beanstalk中定义的环境变量,可以是dev,stg或prd.
我现在的问题是,当从.ebextensions中的配置文件下载配置文件时,如何引用环境名称或ENVIRONMENT变量?
我尝试{"Ref": "AWSEBEnvironmentName" }在.ebextensions/myapp.config中使用引用,但在部署时遇到语法错误.
.ebextensions/myapp.config的内容是:
files:
/config/application-`{"Ref": "AWSEBEnvironmentName" }`.properties:
mode: "000666"
owner: webapp
group: webapp
source: https://s3.amazonaws.com/com.mycompany.mybucket/`{"Ref": "AWSEBEnvironmentName" }`/application-`{"Ref": "AWSEBEnvironmentName" }`.properties
authentication: S3Access
Resources:
AWSEBAutoScalingGroup:
Metadata:
AWS::CloudFormation::Authentication:
S3Access:
type: S3
roleName: aws-elasticbeanstalk-ec2-role
buckets: com.mycompany.api.config
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
The configuration file .ebextensions/myapp.config in application version
manualtest-18 contains invalid YAML or JSON. YAML exception: Invalid Yaml:
mapping values are not allowed here in "<reader>", line 6, column 85:
... .config/stg/application-`{"Ref": …Run Code Online (Sandbox Code Playgroud) environment-variables amazon-web-services amazon-elastic-beanstalk ebextensions
我希望使用 AWS Secrets Manager 来获取机密并将它们设置为我的 Elastic Beanstalk 实例上的环境变量。
我已经在 ebextensions 文件上编写了一个脚本,该脚本调用 Secrets Manager CLI 来获取我的秘密,并使用该秘密来填充我的 EB 实例的 env 变量。由于它是 linux 实例,我正在尝试export ENV_VAR_NAME=env_value. 这是我到目前为止所拥有的:
packages:
yum:
epel-release: []
jq: []
files:
"/home/ec2-user/test.sh" :
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
config=$(aws --region us-west-1 secretsmanager get-secret-value --secret-id secret | jq -rc '.SecretString'')
export SECRET_KEY=$(echo $config | jq -rc '.awsKey')
# Used to print current env variables
env
commands:
0_test:
command: /home/ec2-user/test.sh
#I've also tried replacing 'commands' with 'container_commands' …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-elastic-beanstalk ebextensions aws-secrets-manager
是否有一种干净的方法可以将其他根文件夹添加到使用默认bootRepackage生成的Spring Boot Jar文件中.在我的情况下,我需要AWS beanstalk的.ebextenions文件夹.
我知道我可以破解它 - 例如在bootRepackage之后添加另一个任务来解压缩,重新打包(再次),并重新压缩.有更干净的方式吗?
谢谢
..我试过的两种方式(不起作用):
jar {
from('src/main/ebextensions') {
into('ebextensions')
}
}
bootRepackage {
from('src/main/ebextensions') {
into('ebextensions')
}
}
Run Code Online (Sandbox Code Playgroud) 我的Node.JS项目包含对github上托管的私有NPM repos的引用.这在本地工作正常,但我很难在Elastic Beanstalk上工作.
dependencies: {
...
"express": "^4.12.4",
"jsonwebtoken": "^5.0.5",
"my-private-module": "git@github.com:<my-user>/<my-repo>.git#<my-version>",
...
}
Run Code Online (Sandbox Code Playgroud)
-
我需要的是能够在我的Elastic Beanstalk实例上为git设置一个有效的SSH配置,而不必在源代码控制中存储密钥等.
显然,EB实例没有所需的SSH密钥来访问我的私有github存储库.如果我使用username:password@github.com内联的HTTPS样式git URL ,它可以正常工作.它也可以使用github提供的oauth令牌方法(实际上是用户:pass).但我不希望任何凭据被签入源代码控制,所以我试图从github克隆到我的EB实例上通过SSH工作.
我已经尝试了一百万种方法,包括npm preinstall根据这篇博客文章的脚本,它曾经工作到npm2,其中一个更改使预安装在构建树之后运行,并且修复该问题的PR仍然未决.
我尝试过一个.ebextensions命令配置试图调用git config将insteadofgit@github.com放在一个HTTPS URL中,OAUTH令牌来自一个环境变量(由于env变量在启动时此时未设置,因此本身很棘手)循环,缺少$ HOME使git配置混乱).
我还尝试了各种不同的方法来.ebextensions在我的EB实例上设置SSH,包括来自上述博客文章评论的这个解决方案.这基本上就是我现在被困住的地方.
.ebextensions files配置,可以将我的S3存储桶中的这两个文件复制/tmp/.ssh/到其中commands .ebextensions配置,其中列出了/tmp/.ssh并显示文件是从S3成功下载的:/tmp/.ssh/config包含:
Host github.com
IdentityFile /tmp/.ssh/deploy_key
IdentitiesOnly yes
UserKnownHostsFile=/dev/null
StrictHostKeyChecking no
Run Code Online (Sandbox Code Playgroud)
/tmp/.ssh/deploy_key包含我的私钥,该私钥经过验证可在本地运行.
但是,git仍然会抛出一个错误:
npm ERR! Command failed: git clone --template=/tmp/.npm/_git-remotes/_templates --mirror ssh://git@github.com/[.....] …Run Code Online (Sandbox Code Playgroud) 按照https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/https-singleinstance-php.html上的说明,我一直在尝试添加 SSL 证书以允许我的单实例环境使用 https 。
我在这上面花了很多时间,这让我发疯。
我的重要发现是:
在重新部署并检查 /etc/httpd/conf.d/ 后,我通过 SSH 连接到 EC2 实例进行测试。
我正在运行的平台:PHP 7.4 running on 64bit Amazon Linux 2/3.1.2
这是我第一次使用 SSL 证书以及 AWS,因此我们将不胜感激。
https-instance.config:
packages:
yum:
mod_ssl: []
files:
/etc/pki/tls/certs/server.crt:
mode: "000400"
owner: root
group: root
content: |
-----BEGIN CERTIFICATE-----
1
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
2
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
3
-----END CERTIFICATE-----
/etc/pki/tls/certs/server.key:
mode: "000400"
owner: root …Run Code Online (Sandbox Code Playgroud) apache deployment config amazon-elastic-beanstalk ebextensions
我正在尝试在conainter_commands条目中传递多个命令并不断收到错误.然而,当我传递与单个条目相同的命令时,它工作正常.
作品:
container_commands:
01_remove_old_dump:
command: 'rm -f /tmp/db.dump'
02_get_new_dump:
command: 'aws s3 cp s3://bucket/db.dump'
Run Code Online (Sandbox Code Playgroud)
失败了 /bin/sh: rm -f /tmp/db.dump: No such file or directory.
container_commands:
01_remove_old_dump:
command: ('rm -f /tmp/db.dump' 'aws s3 cp s3://bucket/db.dump')
Run Code Online (Sandbox Code Playgroud) yaml amazon-web-services amazon-elastic-beanstalk ebextensions
ebextensions ×10
java ×2
amazon-s3 ×1
apache ×1
chmod ×1
config ×1
deployment ×1
git ×1
gradle ×1
hook ×1
node.js ×1
spring-boot ×1
ssh ×1
war ×1
yaml ×1