Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

amazon web services - Why am I getting "YAMLException: bad indentation of a mapping entry" on AWS Cloudformation?

I am starting to learn/work with AWS and Cloudformation, I have this:

Type: 'AWS::EC2::Instance'
Properties:
 SecurityGroupIds:
    - !Ref InstanceSecurityGroup
 SubnetId: 
     !Ref "PublicSubnet1"
 IamInstanceProfile:
     !Ref RootInstanceProfile
 ImageId: ami-02cb52d7ba9887a93
 InstanceType: t3.micro
 UserData:
   Fn::Base64: !Sub |
    #!/bin/bash
    # Install Apache Web Server and PHP
      yum install -y httpd mysql
      amazon-linux-extras install -y php7.2
    # Download Lab files
      wget https://us-west-2-tcprod.s3.amazonaws.com/courses/ILT-TF-100-ARCHIT/v6.5.0/lab-2-webapp/scripts/inventory-app.zip
      unzip inventory-app.zip -d /var/www/html/
    # Download and install the AWS SDK for PHP
      wget https://github.com/aws/aws-sdk-php/releases/download/3.62.3/aws.zip
      unzip aws -d /var/www/html
    # Turn on web server
      chkconfig httpd on
      service httpd start

When I try to create the stack I receive an identention error at UserData:

Any advice or tip?

Thank you so much for your help


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use this as an example for writing the userdata in cloudformation template.

Use cfn-linter and the documentation for generating the template, there are plenty of good examples in the documentation as well.

Github Search always results into working examples.

The linter can be installed as a plugin in VS Code or you can run it from your command line the above one.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...