By using AWS re:Post, you agree to the Terms of Use

Running aws cli command in Cloudformation fails

0

Hi,

In Cloudformation I keep getting this error when trying to run a AWS CLI command

Template` contains errors.: Template format error: Unrecognized resource types: `[AWSUtility::CloudFormation::CommandRunner]

This is my CloudFormation template

AWSTemplateFormatVersion: 2010-09-09
Resources:
  Command:
    Type: 'AWSUtility::CloudFormation::Command'
    Properties:
      Command: aws s3 ls | sed -n 1p | cut -d " " -f3 > /command-output.txt
      Role: <ADDED_IAM_ROLE>
Outputs:
    Output:
        Description: The output of the CommandRunner.
        Value: !GetAtt Command.Output

I have added IAM permissions as per documentation https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-awsutilities-commandrunner


                  "cloudformation:ValidateTemplate",
                  "cloudformation:GetTemplateSummary",
                  "cloudformation:*",
                  "s3:CreateBucket",
                  "s3:DeleteBucket",
                  "s3:PutBucketPolicy",
                  "s3:PutObject",
                  "cloudformation:RegisterType",
                  "cloudformation:DescribeTypeRegistration",
                  "iam:createRole"
                ],
                "Resource": ["*"]

Tried Role ARN as well

Any help appreciated :)

1 Answers
1
Accepted Answer

Hi Please see this article for the usage, and pay close attention to the section below

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

Important: If you haven't already registered the AWSUtility::CloudFormation::CommandRunner resource, then run the following commands. The register.sh script uses the awsutility-cloudformation-commandrunner.zip to register the resource type in your AWS Region.

See this GitHub repo for the install instructions

https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-awsutilities-commandrunner#user-installation-steps

Also, your template shows

Resources:
  Command:
    Type: 'AWSUtility::CloudFormation::Command'

Should be

Type: 'AWSUtility::CloudFormation::CommandRunner

profile picture
answered 21 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions