代码之家  ›  专栏  ›  技术社区  ›  mles

如何在Cloudformation中将资源ID导入UserData

  •  0
  • mles  · 技术社区  · 4 年前

    echo ${!Ref EFSFileSystem} 这样地:

      EFSFileSystem:
        Type: AWS::EFS::FileSystem
        Properties:
            ...
    
    
      InstanceLc:
        Type: AWS::AutoScaling::LaunchConfiguration
        Properties:
          ...
          UserData:
            Fn::Base64: !Sub |
              #!/bin/bash -xe
              exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
              aws s3 cp s3://aws-cloudinit/install.sh - | bash
              echo ${!Ref EFSFileSystem}
    

    但在日志中我发现这给了我一个错误:

    /var/lib/cloud/instance/scripts/part-001: line 4: ${Ref EFSFileSystem}: bad substitution
    

    我找到了一些例子。 https://github.com/awslabs/aws-cloudformation-templates/blob/master/community/services/EFS/efs_with_automount_to_ec2.json

    在UserData中导入efs文件系统id的正确语法是什么?

    1 回复  |  直到 4 年前
        1
  •  1
  •   Jason Wadsworth    4 年前

    你有一个 !Sub ${!Ref EFSFileSystem} 你只需要做 ${EFSFileSystem} . 将替换为资源的默认输出,在本例中为 Id .