0
votes

I want to run a bash command in AWS Cloudforamtion. I find this on internet.

 Resources:
    CommandRunner:
        Type: AWSUtility::CloudFormation::CommandRunner
        Properties: 
            Command: 'aws ssm get-parameter --name BucketName --region us-east-1 --query Parameter.Value --output text > /command-output.txt'

I installed this private registry in my was account. When I use this utility, It creates a new stack and starts to deploy new resources like security groups, logs, and EC2 instance.

When it comes to create EC2 instance. It gives an error:

Your requested instance type (t3.micro) is not supported in your requested Availability Zone (us-east-1e). Please retry your request by not specifying an Availability Zone or choosing us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1f. (Service: AmazonEC2; Status Code: 400; Error Code: Unsupported; Request ID: e1f9xyz; Proxy: null)

I followed this link:

https://aws.amazon.com/premiumsupport/knowledge-center/cloudformation-commandrunner-stack/

Can anyone help me with how to run a bash script in a cloud formation template?

1
Did you try re-deploying? - Marcin
Yes. Many times but the same thing happens again and again and there is no option to change the availability zone or region. - Shahzaib Butt
You can specify SubnetId. So choose subnet in AZ where t3.micros are available. - Marcin
Probably you are trying to run the AWSUtility script in us-east-1e AZ and the EC2 instanceType t3.micro is not present there. - mshikher

1 Answers

0
votes

Try this,

AWSTemplateFormatVersion: 2010-09-09
Resources:
  RunCommandTitle:
    Type: AWSUtility::CloudFormation::CommandRunner
    Properties:
      Command: echo "Success" > /command-output.txt
      SubnetId: subnet-XXX
      SecurityGroupId: sg-XXX
Outputs:
  Output:
      Description: The output of the command.
      Value: !GetAtt RunCommandTitle.Output