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 }}"
        }
      }
    }
  ]
}
asked 5 years ago3188 views
6 Answers
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
answered 5 years ago
0

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

Regards,

answered 5 years ago
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
answered 4 years ago
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
answered 3 years ago
0

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

SeldaA
answered 3 years ago
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
answered 3 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