amazon-web-services - 我试图在 cloudformation 中获取一个文件以在 ec2 实例中生成,但似乎无法在 ec2 实例上看到它

标签 amazon-web-services amazon-ec2 aws-cloudformation

目前,我尝试简单地启动一个 ec2 实例,以在当前云形成启动的 tmp 文件夹中显示 myfile2.txt。但没有文件。我尝试在命令行中解决问题并检查日志,但我不明白问题是什么。我在 AWS::CloudFormation::Init: 方面遇到了麻烦有一段时间了,想知道是否有人有任何建议? ?

这只是一个简单的练习,是一个更大项目的一部分。

AWSTemplateFormatVersion: "2010-09-09"
Parameters:
  InstanceTypeParameter:
    Type: String
    Default: t2.micro
    AllowedValues:
      - t2.micro
      - m1.small
      - m1.large
    Description: Enter t2.micro, m1.small, or m1.large. Default is t2.micro.
  KeyName:
    Description: key pair name
    Type: AWS::EC2::KeyPair::KeyName

Resources:
  WebInstance:
    Type: AWS::EC2::Instance
    Metadata:
        AWS::CloudFormation::Init:
          config:
            files:
              '/tmp/myfile2.txt':
                content: "Hello sir"
                mode: '000755'
                owner: root
                group: root
    Properties:
        InstanceType:
          Ref: InstanceTypeParameter
        ImageId:  ami-04b762b4289fba92b
        SecurityGroupIds:
          - sg-0394c353eef246c71
        SubnetId: subnet-476a773e
        Tags:
          -
            Key: Name
            Value: Trovo-webserver
        KeyName:
          Ref: KeyName
        UserData:
          Fn::Base64:
            !Sub |
              #!/bin/bash -xe

最佳答案

尚不清楚您是否正在运行 cfn-init 命令。理想情况下,您的 userdata 部分将有一个命令 cfn-init ,该命令反过来会调用 Init 键下定义的配置集。请检查下面的示例片段。

UserData: !Base64 
  'Fn::Join':
    - ''
    - - |
        #!/bin/bash -xe
      - |
        # Install the files and packages from the metadata
      - '/opt/aws/bin/cfn-init -v '
      - '         --stack '
      - !Ref 'AWS::StackName'
      - '         --resource WebServerInstance '
      - '         --configsets InstallAndRun '
      - '         --region '
      - !Ref 'AWS::Region'
      - |+

关于amazon-web-services - 我试图在 cloudformation 中获取一个文件以在 ec2 实例中生成,但似乎无法在 ec2 实例上看到它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58086116/

相关文章:

amazon-web-services - AWS - 错误 - 更新 Auto Scaling 组、Amazon CloudFormation、无法部署配置

yaml - CloudFormation yaml - 如何强制数字类型?

mysql - 使用 Terraform 为 RDS 创建 Route53 条目

java - AWS ResetException - 无法重置请求输入流

amazon-ec2 - Spark - AWS EMR 集群首选哪种实例类型?

MySQL远程连接(复制)

node.js - 如何使用opsWorks在aws上部署nodejs?

aws-lambda - 当代码版本插入 CloudFormation 模板中的 Handler 属性时,Lambda 找不到文件

python - 使用 aws-cdk(python) 更新 Redis 集群的问题

python - 尝试使用python读取s3内容中按时间排序的所有文件