1

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?

4
  • 2
    Did you try re-deploying? Commented Jun 15, 2021 at 11:02
  • Yes. Many times but the same thing happens again and again and there is no option to change the availability zone or region. Commented Jun 16, 2021 at 10:29
  • You can specify SubnetId. So choose subnet in AZ where t3.micros are available. Commented Jun 16, 2021 at 10:31
  • Probably you are trying to run the AWSUtility script in us-east-1e AZ and the EC2 instanceType t3.micro is not present there. Commented Jul 12, 2021 at 22:58

1 Answer 1

1

Try this,

Follow the Installation section here

Specifying the region and role (Instance Profile name. Not the role name. In case they are different) are important to execute AWS CLI commands

AWSTemplateFormatVersion: 2010-09-09
Resources:
  RunCommandTitle:
    Type: AWSUtility::CloudFormation::CommandRunner
    Properties:
      Command: aws s3 ls --region us-east-1 && echo Success > /command-output.txt
      Role: your-EC2-Instance-Profile-name
      SubnetId: subnet-XXX
      SecurityGroupId: sg-XXX
Outputs:
  Output:
      Description: The output of the command.
      Value: !GetAtt RunCommandTitle.Output
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.