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
posta 2 anni fa1674 visualizzazioni
1 Risposta
2
Risposta accettata

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
ESPERTO
Matt-B
con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande