0

I have created a cloud formation script

# in mumbai region (working)
Resources:
  MyNewEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-0fcbc9ed97efe271e
      InstanceType: t2.micro
      SubnetId: subnet-fc2df495
      KeyName: sant-test
      UserData:
        Fn::Base64:
          Fn::Sub: |
          #!/bin/bash -xe
          yum update -y
          echo somenthing:khskhsdh >> test.txt

this is throwing error at echo somenthing:khskhsdh >> test.txt

enter image description here

i get error something like:

enter image description here

How to handle special characters

Santhosh
  • 9,965
  • 20
  • 103
  • 243

1 Answers1

1

I looked up all my templates and found an example that works 100%:

Resources:
  MyNewEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-0fcbc9ed97efe271e
      InstanceType: t2.micro
      SubnetId: subnet-fc2df495
      KeyName: sant-test
      UserData:
        Fn::Base64: |-
          #!/bin/bash
          yum update -y
          echo somenthing:khskhsdh >> test.txt

The Fn::Sub: in the question is redundant and causing an error.

Vasyl Herman
  • 414
  • 2
  • 11
  • Hi where can i check the logs to check whether the bash script got executed successfully – Santhosh Jul 20 '23 at 10:38
  • Sure, see here https://stackoverflow.com/questions/15904095/how-to-check-whether-my-user-data-passing-to-ec2-instance-is-working – Vasyl Herman Jul 20 '23 at 12:04
  • 1
    @Santhosh that is a different question. if this question has been resolved by this answer, consider upvoting/accepting this answer – Paolo Jul 20 '23 at 18:28