我有以下 aws cloudformation 模板,我需要在 EC2 启动模板部分中执行字符串操作(其中 URL 是 cfn 模板参数)-
UserData:
Fn::Base64: !Join
- ''
- - !Sub |
#!/bin/bash
set -o xtrace
.
.
git clone ${URL}
- |
CFNREPO=${URL/aws.*/aws-cfn.git}
git clone ${CFNREPO}
- !Sub |
GITHUBURL: ${githubURL}
.
.
预期输出:
#!/bin/bash
set -o xtrace
.
.
git clone https://www.example.com/aws-s3.git
CFNREPO=https://www.example.com/aws-cfn.git
git clone https://www.example.com/aws-cfn.git
GITHUBURL: https://github.com/other-repo-url
.
.
实际输出:
#!/bin/bash
set -o xtrace
.
.
git clone https://www.example.com/aws-s3.git
CFNREPO=${URL/aws.*/aws-cfn.git}
git clone ${CFNREPO}
GITHUBURL: https://github.com/other-repo-url
.
.
推荐 - link ,但解决方案并未按预期工作。
最佳答案
您的代码是正确的,至少从 yaml 的角度来看是这样。这部分:
CFNREPO=${URL/aws.*/aws-cfn.git}
git clone ${CFNREPO}
将在您在实例上运行代码时解决。这不是 YAML 或 CloudFormation 可以为您做的事情。
关于amazon-web-services - Fn::Sub 与 Bash 参数替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69483013/