handling output of runbook in ssm


hello there, I am trying to make a custom runbook in ssm. my custom runbook uses another runbook as one of its steps namely "AWSSupport-CopyEC2Instance". based on AWS documents, the runbook has 3 outputs: "sameRegionLaunchInstanceWithKeyPair.InstanceIds" "sameRegionLaunchInstanceWithoutKeyPair.InstanceIds" "destinationRegionLaunchInstance.DestinationInstanceId" I want to use the second output and pass it to the next step to process. in the first runbook i set the output as: name of output: DestinationInstanceId selector: $.Payload.sameRegionLaunchInstanceWithoutKeyPair.InstanceIds

the problem is that, when I pass it to the next runbook, instead of the value of ec2 instance id, it returns the actual name: "{{ AWSSupport_CopyEC2Instance.DestinationInstanceId }}". what should i do to resolve the problem? please guide me

asked 3 months ago136 views
1 Answer

Dear Customer, Hope you are doing good!!

It seems like you're encountering an issue where the output variable name is being passed instead of its value when using a custom runbook in AWS Systems Manager (SSM).

When referencing the output variable in the subsequent steps of your custom runbook, use the correct syntax to access its value. In AWS Systems Manager Automation documents, you typically use the following syntax to access output variables: {{ OutputName.Payload.VariableName }}.

Replace "OutputName" with the name of the output and "VariableName" with the name of the variable within that output.

In your case, the correct syntax to reference the second output variable would be: {{ AWSSupport_CopyEC2Instance.sameRegionLaunchInstanceWithoutKeyPair.InstanceIds.Payload }}.

I am providing you a sample code for your reference

description: "Custom Runbook"
schemaVersion: "0.3"
name: "InstanceId"
    type: "String"
    description: "Instance ID"
    default: ""
name: "Step1"
      actionType: "aws:executeScript"
"echo 'Executing Step 1'"
    name: "Step 1"
name: "Step2"
      actionType: "aws:executeScript"
"echo 'Executing Step 2 with Instance ID: {{ InstanceId }}'"
    name: "Step 2"
name: "Step3"
      actionType: "aws:executeScript"
"echo 'Executing Step 3 with DestinationInstanceId: {{ AWSSupport_CopyEC2Instance.sameRegionLaunchInstanceWithoutKeyPair.InstanceIds.Payload }}'"
    name: "Step 3" 

answered a month 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