AWS Cloudformation 中 UserData 中的参考参数值

葡萄藤

我在参数部分有这个,

Parameters:
  PlatformSelect:
    Description: Cockpit platform Select.
    Type: String
    Default: qa-1
    AllowedValues: [qa-1, qa-2, staging, production]

我需要在我的 UserData 中引用这个值。我在两者之间使用映射。

Mappings:
  bootstrap:
    ubuntu:
      print: echo ${PlatformSelect} >>test.txt

Resources:
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: !Ref ‘InstanceType’
      KeyName: !Ref ‘KeyName’
      Tags:
      - Key: Name
        Value: Test
      UserData:
        Fn::Base64:
          Fn::Join:
          - ‘’
          - - |
              #!/bin/bash
            - Fn::FindInMap:
              - bootstrap
              - ubuntu
              - print
            - |2+

这是行不通的。不确定我引用它的方式是错误的!!

我应该在它之前使用诸如 '${AWS::Parameters:PlatformSelect}' 之类的东西吗?

麦凯

你有什么理由Mapping在两者之间使用吗?

你可以很容易地使用!Sub,而不是

Resources:
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: !Ref InstanceType
      KeyName: !Ref KeyName
      Tags:
        - Key: Name
          Value: Test
      UserData:
        Fn::Base64:
          !Sub |
            #!/bin/bash
            ${PlatformSelect}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

YAML Cloudformation模板中UserData的引用角色

Cloudformation无法识别UserData脚本中的Shell变量

Cloudformation中如何将Resource ID导入UserData

Userdata Cloudformation中资源的参考ID

AWS中的Cloudformation / Serverless与Terraform

如何在 UserData 中的 Cloudformation Fn::Sub 中添加两个变量

为多个实例重用AWS :: CloudFormation :: Init(和userdata?)

未在AWS CloudFormation模板上执行Userdata脚本

docker pull <image> 在 cloudformation UserData 標籤中不起作用

Cloudformation错误:属性验证失败:[{/}中遇到了不受支持的属性:[UserData]]

无法在 AWS 中验证或上传 CloudFormation 模板

在aws cloudformation模板中引用“ Self”?

在Spring Cloud AWS中禁用Cloudformation

遍历模板中的AWS Cloudformation资源阵列

如何在cloudformation中过滤aws资源

CloudFormation中的AWS :: CloudFront :: OriginRequestPolicy资源

是否可以在AWS CloudFormation启动URL中设置参数?

AWS Cloudformation 快速创建链接未读取 URL 中的参数

我无法使用CloudFormation中的Userdata将S3文件复制到EC2实例

CloudFormation UserData 模板,用於在 EC2 的配置文件中寫入 RDS 端點

尝试在CloudFormation中的UserData中使用变量时出现错误“一个或多个Fn :: Sub内部函数未指定期望的参数”

docker-compose exec python输入的设备不是AWS EC2 UserData中的TTY

AWS EC2 - yum 更新在 AutoScaling LaunchConfig UserData 中不起作用

AWS CloudFormation UserData:如何在脚本中使用局部变量

AWS CloudFormation UserData EC2环境变量

如何使用!Sub或!Join在文件密钥“ AWS :: CloudFormation :: Init”中

使用 cloudformation 从 eks 集群在 aws 中创建 OIDC 提供程序

AWS CDK是否在CloudFormation中创建默认堆栈名称?

在AWS CloudFormation中定义表,视图和索引