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 }}"
        }
      }
    }
  ]
}
gefragt vor 5 Jahren3216 Aufrufe
6 Antworten
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
beantwortet vor 5 Jahren
0

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

Regards,

beantwortet vor 5 Jahren
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
beantwortet vor 4 Jahren
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
beantwortet vor 3 Jahren
0

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

SeldaA
beantwortet vor 3 Jahren
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
beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen