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 :)

AzCodez
asked 2 years ago1662 views
1 Answer
2
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 pictureAWS
EXPERT
Matt-B
answered 2 years 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