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 }}"
        }
      }
    }
  ]
}
demandé il y a 5 ans3216 vues
6 réponses
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
répondu il y a 5 ans
0

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

Regards,

répondu il y a 5 ans
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
répondu il y a 4 ans
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
répondu il y a 3 ans
0

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

SeldaA
répondu il y a 3 ans
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
répondu il y a 3 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions