handling output of runbook in ssm

0

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

Aref
已提問 3 個月前檢視次數 130 次
1 個回答
0

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"
parameters:
name: "InstanceId"
    type: "String"
    description: "Instance ID"
    default: ""
mainSteps:
name: "Step1"
    action:
      actionType: "aws:executeScript"
      inputs:
        runCommand:
"echo 'Executing Step 1'"
    name: "Step 1"
name: "Step2"
    action:
      actionType: "aws:executeScript"
      inputs:
        runCommand:
"echo 'Executing Step 2 with Instance ID: {{ InstanceId }}'"
    name: "Step 2"
name: "Step3"
    action:
      actionType: "aws:executeScript"
      inputs:
        runCommand:
"echo 'Executing Step 3 with DestinationInstanceId: {{ AWSSupport_CopyEC2Instance.sameRegionLaunchInstanceWithoutKeyPair.InstanceIds.Payload }}'"
    name: "Step 3" 

Damini
已回答 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南