How to cast parameter types for Automation steps?

0

I have an Automation Document snippet which attempts to:

Update AMI used by the specified Launch Template.

Create a new version of the Launch Template with the updated AMI.

However, I get the following errors at the last step:

Parameter validation failed:
Invalid type for parameter LaunchTemplateData.ImageId, value: ['ami-XXXX'], type: <class 'list'>, valid types: <class 'str'>
Invalid type for parameter SourceVersion, value: 5, type: <class 'int'>, valid types: <class 'str'>

Is there a way to cast/convert/manipulate parameter types?

Thank you.

{
  "parameters": {
    "LaunchTemplateId": {
      "type": "String"
    },
    "TargetAmiName": {
      "type": "String"
    }
  },
  "mainSteps": [
    {
      "name": "getLaunchTemplate",
      "action": "aws:executeAwsApi",
      "inputs": {
        "Service": "ec2",
        "Api": "DescribeLaunchTemplateVersions",
        "LaunchTemplateId": "{{ LaunchTemplateId }}"
      },
      "outputs": [
        {
          "Name": "Version",
          "Selector": "$.LaunchTemplateVersions[0].VersionNumber",
          "Type": "Integer"
        },
        {
          "Name": "ImageId",
          "Selector": "$.LaunchTemplateVersions[0].LaunchTemplateData.ImageId",
          "Type": "String"
        }
      ]
    },
    {
      "name": "updateWindowsAmi",
      "action": "aws:executeAutomation",
      "inputs": {
        "DocumentName": "AWS-UpdateWindowsAmi",
        "RuntimeParameters": {
          "SourceAmiId": "{{ getLaunchTemplate.ImageId }}",
          "IamInstanceProfileName": "ManagedInstanceProfile",
          "AutomationAssumeRole": "arn:aws:iam::{{global:ACCOUNT_ID}}:role/AutomationServiceRole",
          "TargetAmiName": "{{ TargetAmiName }}"
        }
      }
    },
    {
      "name": "createTemplateVersion",
      "action": "aws:executeAwsApi",
      "inputs": {
        "Service": "ec2",
        "Api": "CreateLaunchTemplateVersion",
        "LaunchTemplateId": "{{ LaunchTemplateId }}",
        "SourceVersion": "{{ getLaunchTemplate.Version }}",
        "LaunchTemplateData": {
          "ImageId": "{{ updateWindowsAmi.Output }}"
        }
      }
    }
  ]
}
質問済み 5年前3216ビュー
6回答
0

Thank you for your query. Systems Manager Automation currently does not support casting/converting parameter types. We appreciate your feedback and will add this to our backlog of feature requests.

AWS
回答済み 5年前
0

Thank you for the reply.
I'm looking forward to the feature. In the meantime, I perform the last step manually.

Regards,

回答済み 5年前
0

Does AWS have an ETA?

The lack of casting is problematic when passing data between APIs. For example, the ec2 ModifyVolume API requires Size to be an integer. And subsequently if I want to send a message to SNS, "Volume {{ VolumeId }} was resized to {{ Size }}" I get a cast error - Parameter "Size" is "INTEGER" type and can't be used as a substring parameter.

hcbphil
回答済み 4年前
0

Hi @s-morita,
How did you sort out that issue? I am getting same error for SourceVersion parameter and can not sort out it.
Would you please guide me?
Thanks

SeldaA
回答済み 3年前
0

Hi Varsha-AWS,
is there any update about that topic? i am getting same error.
Thanks

SeldaA
回答済み 3年前
0

Hi SeldaA,

Apologies for the delay in our response.

We support executing Python or Powershell scripts as part of the Automation runbook workflow. Using this, you can cast the parameters to the appropriate data types before making the API call in the last step. In this case, you can use the aws:executeScript step as the intermediate step to perform the required transformations and pass the transformed value as the input to the next step.

Regards,
Dharmi

AWS
回答済み 3年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ