amazon-web-services - Fn::Sub 与 Bash 参数替换

标签 amazon-web-services aws-cloudformation

我有以下 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/

相关文章:

aws-cloudformation - 如何删除正在使用导出的 CloudFormation 堆栈?

linux - 使用yaml文件和boto3在aws云上配置Linux服务器

amazon-web-services - 如何防止重复的 SQS 消息?

amazon-web-services - kubectl exec/logs on EKS 返回 "remote error: tls: internal error"

amazon-web-services - 错误 : NotAuthorizedError - Operation Denied on AWS eb init

json - 在 cloudformation 中的 yaml 内的 json 中使用 Fn::ImportValue

amazon-s3 - 用于分析 s3 日志的 Amazon Elastic Map Reduce

bash - 如何临时切换 AWS CLI 的配置文件?

aws-cloudformation - 如果 sam 模板位于 API Gateway DefinitionBody 中作为响应示例,如何让 null 值传入 sam 模板

ruby-on-rails - 部署ruby-on-rails项目时出现错误 "Property Listeners cannot be empty"