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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则