Pass variable into Step Function start_execution() input parameterHow to flush output of print function?boto3 - Step Functions generate_presigned_url InvalidSignatureExceptionPassthrough input to output in AWS Step Functionshow to pass input to multiple ARNs (aws step function)?Send Input as Output on error for AWS Step FunctionPython Step Functions API: get_activity_task seems to always timeoutHow to insert the input from a step to a json struct and pass to next step in step functions?Pass and use input (parameters) to a lambda task from a step functionHow to pass Step Function input to Batch JobPassing data to step function catch

Why would the President need briefings on UFOs?

Have only girls been born for a long time in this village?

Is a butterfly one or two animals?

In xXx, is Xander Cage's 10th vehicle a specific reference to another franchise?

Repurpose telephone line to ethernet

How to detect a failed AES256 decryption programmatically?

Can a Beast Master ranger choose a swarm as an animal companion?

What is the latest version of SQL Server native client that is compatible with Sql Server 2008 r2

Does C++20 mandate source code being stored in files?

Use of vor in this sentence

Writing/buying Seforim rather than Sefer Torah

What is a "click" in Greek or Latin?

Stuffing in the middle

Color the polygons in PolyhedronData

"Silverware", "Tableware", and "Dishes"

Is refusing to concede in the face of an unstoppable Nexus combo punishable?

!I!n!s!e!r!t! !n!b!e!t!w!e!e!n!

Does git delete empty folders?

How much code would a codegolf golf if a codegolf could golf code?

Are illustrations in novels frowned upon?

Don't teach Dhamma to those who can't appreciate it or aren't interested

Why do some academic journals requires a separate "summary" paragraph in addition to an abstract?

How does the Saturn V Dynamic Test Stand work?

Alchemist potion on Undead



Pass variable into Step Function start_execution() input parameter


How to flush output of print function?boto3 - Step Functions generate_presigned_url InvalidSignatureExceptionPassthrough input to output in AWS Step Functionshow to pass input to multiple ARNs (aws step function)?Send Input as Output on error for AWS Step FunctionPython Step Functions API: get_activity_task seems to always timeoutHow to insert the input from a step to a json struct and pass to next step in step functions?Pass and use input (parameters) to a lambda task from a step functionHow to pass Step Function input to Batch JobPassing data to step function catch






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am using boto3 with Python 3.6 to start a Step Function execution. The Step Function is designed to share my base AMI across all my accounts. I have 4 variables I need to pass to the input parameter to kick off the execution. These are the AMI ID, the account list of accounts I own, the source account, and the KMS key. The AMI ID and the account list are constructed in my code and are the variables that need to get passed dynamically. According to the documentation, input is a string that contains the JSON input data for the execution and gives the following example: "input": ""ami_id" : "ami_id"". My question is how do I pass the variables in question to this parameter as the value? My code is below with the traceback:



CODE:



import boto3
import json

# Get an STS token to assume roles into AWS accounts
def get_sts_token(**kwargs):
role_arn = kwargs['RoleArn']
region_name = kwargs['RegionName']
sts = boto3.client(
'sts',
region_name=region_name,
)
token = sts.assume_role(
RoleArn=role_arn,
RoleSessionName='GetInstances',
DurationSeconds=900,
)
return token["Credentials"]

def get_accounts():
role_arn = "arn:aws:iam::xxxxxxxxxx:role/list-accounts-role"
region_name = "us-east-1"

token = get_sts_token(RoleArn=role_arn, RegionName=region_name)

access_key = token['AccessKeyId']
secret_key = token['SecretAccessKey']
session_token = token['SessionToken']

client = boto3.client('organizations',
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
aws_session_token=session_token)

moreAccounts=True
nexttoken=''
global accountList
accountList =[]

while moreAccounts:
if (len(nexttoken)>0):
accounts=client.list_accounts(NextToken=nexttoken)
else:
accounts=client.list_accounts()
if 'NextToken' in accounts:
nexttoken=accounts['NextToken']
else:
moreAccounts=False
for account in accounts['Accounts']:
if account['Status'] != 'SUSPENDED' and account['Status'] != 'CLOSED' :
account_id = account['Id']
accountList.append(account_id)


print(accountList)

def trigger_sfn():
ssm = boto3.client('ssm')
role_arn = "arn:aws:iam::xxxxxxxx:role/execute-sfn"
region_name = "us-east-1"

ami_id = ssm.get_parameter(Name='/BaseAMI/newest')['Parameter']['Value']
print(ami_id)

token = get_sts_token(RoleArn=role_arn, RegionName=region_name)
print(token)

access_key = token['AccessKeyId']
secret_key = token['SecretAccessKey']
session_token = token['SessionToken']

sfn = boto3.client('stepfunctions',
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
aws_session_token=session_token)

response = sfn.start_execution(
stateMachineArn='arn:aws:states:us-east-1:xxxxxxxx:stateMachine:ami-share',
input=""ami_id": ami_id, "source_account_id": "112233445566", "accountList": accountList, "kms_key_arn": "alias/aws/ebs""
)

print(response)


TRACE:



An error occurred (InvalidExecutionInput) when calling the 
StartExecution operation: Invalid State Machine Execution Input:
'com.fasterxml.jackson.core.JsonParseException: Unrecognized token
'ami_id': was expecting ('true', 'false' or 'null')
at [Source: (String)""ami_id": ami_id, "source_account_id":
"112233445566", "accountList": accountList, "kms_key_arn":
"alias/aws/ebs""; line: 1, column: 18]': InvalidExecutionInput
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 6, in lambda_handler
trigger_sfn()
File "/var/task/lambda_function.py", line 96, in trigger_sfn
input=""ami_id": ami_id, "source_account_id": "112233445566",
"accountList": accountList, "kms_key_arn": "alias/aws/ebs""
File "/var/runtime/botocore/client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 612, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidExecutionInput: An error occurred
(InvalidExecutionInput) when calling the StartExecution operation:
Invalid State Machine Execution Input:
'com.fasterxml.jackson.core.JsonParseException: Unrecognized token
'ami_id': was expecting ('true', 'false' or 'null')
at [Source: (String)""ami_id": ami_id, "source_account_id":
"112233445566", "accountList": accountList, "kms_key_arn":
"alias/aws/ebs""; line: 1, column: 18]'









share|improve this question
































    0















    I am using boto3 with Python 3.6 to start a Step Function execution. The Step Function is designed to share my base AMI across all my accounts. I have 4 variables I need to pass to the input parameter to kick off the execution. These are the AMI ID, the account list of accounts I own, the source account, and the KMS key. The AMI ID and the account list are constructed in my code and are the variables that need to get passed dynamically. According to the documentation, input is a string that contains the JSON input data for the execution and gives the following example: "input": ""ami_id" : "ami_id"". My question is how do I pass the variables in question to this parameter as the value? My code is below with the traceback:



    CODE:



    import boto3
    import json

    # Get an STS token to assume roles into AWS accounts
    def get_sts_token(**kwargs):
    role_arn = kwargs['RoleArn']
    region_name = kwargs['RegionName']
    sts = boto3.client(
    'sts',
    region_name=region_name,
    )
    token = sts.assume_role(
    RoleArn=role_arn,
    RoleSessionName='GetInstances',
    DurationSeconds=900,
    )
    return token["Credentials"]

    def get_accounts():
    role_arn = "arn:aws:iam::xxxxxxxxxx:role/list-accounts-role"
    region_name = "us-east-1"

    token = get_sts_token(RoleArn=role_arn, RegionName=region_name)

    access_key = token['AccessKeyId']
    secret_key = token['SecretAccessKey']
    session_token = token['SessionToken']

    client = boto3.client('organizations',
    aws_access_key_id=access_key,
    aws_secret_access_key=secret_key,
    aws_session_token=session_token)

    moreAccounts=True
    nexttoken=''
    global accountList
    accountList =[]

    while moreAccounts:
    if (len(nexttoken)>0):
    accounts=client.list_accounts(NextToken=nexttoken)
    else:
    accounts=client.list_accounts()
    if 'NextToken' in accounts:
    nexttoken=accounts['NextToken']
    else:
    moreAccounts=False
    for account in accounts['Accounts']:
    if account['Status'] != 'SUSPENDED' and account['Status'] != 'CLOSED' :
    account_id = account['Id']
    accountList.append(account_id)


    print(accountList)

    def trigger_sfn():
    ssm = boto3.client('ssm')
    role_arn = "arn:aws:iam::xxxxxxxx:role/execute-sfn"
    region_name = "us-east-1"

    ami_id = ssm.get_parameter(Name='/BaseAMI/newest')['Parameter']['Value']
    print(ami_id)

    token = get_sts_token(RoleArn=role_arn, RegionName=region_name)
    print(token)

    access_key = token['AccessKeyId']
    secret_key = token['SecretAccessKey']
    session_token = token['SessionToken']

    sfn = boto3.client('stepfunctions',
    aws_access_key_id=access_key,
    aws_secret_access_key=secret_key,
    aws_session_token=session_token)

    response = sfn.start_execution(
    stateMachineArn='arn:aws:states:us-east-1:xxxxxxxx:stateMachine:ami-share',
    input=""ami_id": ami_id, "source_account_id": "112233445566", "accountList": accountList, "kms_key_arn": "alias/aws/ebs""
    )

    print(response)


    TRACE:



    An error occurred (InvalidExecutionInput) when calling the 
    StartExecution operation: Invalid State Machine Execution Input:
    'com.fasterxml.jackson.core.JsonParseException: Unrecognized token
    'ami_id': was expecting ('true', 'false' or 'null')
    at [Source: (String)""ami_id": ami_id, "source_account_id":
    "112233445566", "accountList": accountList, "kms_key_arn":
    "alias/aws/ebs""; line: 1, column: 18]': InvalidExecutionInput
    Traceback (most recent call last):
    File "/var/task/lambda_function.py", line 6, in lambda_handler
    trigger_sfn()
    File "/var/task/lambda_function.py", line 96, in trigger_sfn
    input=""ami_id": ami_id, "source_account_id": "112233445566",
    "accountList": accountList, "kms_key_arn": "alias/aws/ebs""
    File "/var/runtime/botocore/client.py", line 314, in _api_call
    return self._make_api_call(operation_name, kwargs)
    File "/var/runtime/botocore/client.py", line 612, in _make_api_call
    raise error_class(parsed_response, operation_name)
    botocore.errorfactory.InvalidExecutionInput: An error occurred
    (InvalidExecutionInput) when calling the StartExecution operation:
    Invalid State Machine Execution Input:
    'com.fasterxml.jackson.core.JsonParseException: Unrecognized token
    'ami_id': was expecting ('true', 'false' or 'null')
    at [Source: (String)""ami_id": ami_id, "source_account_id":
    "112233445566", "accountList": accountList, "kms_key_arn":
    "alias/aws/ebs""; line: 1, column: 18]'









    share|improve this question




























      0












      0








      0








      I am using boto3 with Python 3.6 to start a Step Function execution. The Step Function is designed to share my base AMI across all my accounts. I have 4 variables I need to pass to the input parameter to kick off the execution. These are the AMI ID, the account list of accounts I own, the source account, and the KMS key. The AMI ID and the account list are constructed in my code and are the variables that need to get passed dynamically. According to the documentation, input is a string that contains the JSON input data for the execution and gives the following example: "input": ""ami_id" : "ami_id"". My question is how do I pass the variables in question to this parameter as the value? My code is below with the traceback:



      CODE:



      import boto3
      import json

      # Get an STS token to assume roles into AWS accounts
      def get_sts_token(**kwargs):
      role_arn = kwargs['RoleArn']
      region_name = kwargs['RegionName']
      sts = boto3.client(
      'sts',
      region_name=region_name,
      )
      token = sts.assume_role(
      RoleArn=role_arn,
      RoleSessionName='GetInstances',
      DurationSeconds=900,
      )
      return token["Credentials"]

      def get_accounts():
      role_arn = "arn:aws:iam::xxxxxxxxxx:role/list-accounts-role"
      region_name = "us-east-1"

      token = get_sts_token(RoleArn=role_arn, RegionName=region_name)

      access_key = token['AccessKeyId']
      secret_key = token['SecretAccessKey']
      session_token = token['SessionToken']

      client = boto3.client('organizations',
      aws_access_key_id=access_key,
      aws_secret_access_key=secret_key,
      aws_session_token=session_token)

      moreAccounts=True
      nexttoken=''
      global accountList
      accountList =[]

      while moreAccounts:
      if (len(nexttoken)>0):
      accounts=client.list_accounts(NextToken=nexttoken)
      else:
      accounts=client.list_accounts()
      if 'NextToken' in accounts:
      nexttoken=accounts['NextToken']
      else:
      moreAccounts=False
      for account in accounts['Accounts']:
      if account['Status'] != 'SUSPENDED' and account['Status'] != 'CLOSED' :
      account_id = account['Id']
      accountList.append(account_id)


      print(accountList)

      def trigger_sfn():
      ssm = boto3.client('ssm')
      role_arn = "arn:aws:iam::xxxxxxxx:role/execute-sfn"
      region_name = "us-east-1"

      ami_id = ssm.get_parameter(Name='/BaseAMI/newest')['Parameter']['Value']
      print(ami_id)

      token = get_sts_token(RoleArn=role_arn, RegionName=region_name)
      print(token)

      access_key = token['AccessKeyId']
      secret_key = token['SecretAccessKey']
      session_token = token['SessionToken']

      sfn = boto3.client('stepfunctions',
      aws_access_key_id=access_key,
      aws_secret_access_key=secret_key,
      aws_session_token=session_token)

      response = sfn.start_execution(
      stateMachineArn='arn:aws:states:us-east-1:xxxxxxxx:stateMachine:ami-share',
      input=""ami_id": ami_id, "source_account_id": "112233445566", "accountList": accountList, "kms_key_arn": "alias/aws/ebs""
      )

      print(response)


      TRACE:



      An error occurred (InvalidExecutionInput) when calling the 
      StartExecution operation: Invalid State Machine Execution Input:
      'com.fasterxml.jackson.core.JsonParseException: Unrecognized token
      'ami_id': was expecting ('true', 'false' or 'null')
      at [Source: (String)""ami_id": ami_id, "source_account_id":
      "112233445566", "accountList": accountList, "kms_key_arn":
      "alias/aws/ebs""; line: 1, column: 18]': InvalidExecutionInput
      Traceback (most recent call last):
      File "/var/task/lambda_function.py", line 6, in lambda_handler
      trigger_sfn()
      File "/var/task/lambda_function.py", line 96, in trigger_sfn
      input=""ami_id": ami_id, "source_account_id": "112233445566",
      "accountList": accountList, "kms_key_arn": "alias/aws/ebs""
      File "/var/runtime/botocore/client.py", line 314, in _api_call
      return self._make_api_call(operation_name, kwargs)
      File "/var/runtime/botocore/client.py", line 612, in _make_api_call
      raise error_class(parsed_response, operation_name)
      botocore.errorfactory.InvalidExecutionInput: An error occurred
      (InvalidExecutionInput) when calling the StartExecution operation:
      Invalid State Machine Execution Input:
      'com.fasterxml.jackson.core.JsonParseException: Unrecognized token
      'ami_id': was expecting ('true', 'false' or 'null')
      at [Source: (String)""ami_id": ami_id, "source_account_id":
      "112233445566", "accountList": accountList, "kms_key_arn":
      "alias/aws/ebs""; line: 1, column: 18]'









      share|improve this question
















      I am using boto3 with Python 3.6 to start a Step Function execution. The Step Function is designed to share my base AMI across all my accounts. I have 4 variables I need to pass to the input parameter to kick off the execution. These are the AMI ID, the account list of accounts I own, the source account, and the KMS key. The AMI ID and the account list are constructed in my code and are the variables that need to get passed dynamically. According to the documentation, input is a string that contains the JSON input data for the execution and gives the following example: "input": ""ami_id" : "ami_id"". My question is how do I pass the variables in question to this parameter as the value? My code is below with the traceback:



      CODE:



      import boto3
      import json

      # Get an STS token to assume roles into AWS accounts
      def get_sts_token(**kwargs):
      role_arn = kwargs['RoleArn']
      region_name = kwargs['RegionName']
      sts = boto3.client(
      'sts',
      region_name=region_name,
      )
      token = sts.assume_role(
      RoleArn=role_arn,
      RoleSessionName='GetInstances',
      DurationSeconds=900,
      )
      return token["Credentials"]

      def get_accounts():
      role_arn = "arn:aws:iam::xxxxxxxxxx:role/list-accounts-role"
      region_name = "us-east-1"

      token = get_sts_token(RoleArn=role_arn, RegionName=region_name)

      access_key = token['AccessKeyId']
      secret_key = token['SecretAccessKey']
      session_token = token['SessionToken']

      client = boto3.client('organizations',
      aws_access_key_id=access_key,
      aws_secret_access_key=secret_key,
      aws_session_token=session_token)

      moreAccounts=True
      nexttoken=''
      global accountList
      accountList =[]

      while moreAccounts:
      if (len(nexttoken)>0):
      accounts=client.list_accounts(NextToken=nexttoken)
      else:
      accounts=client.list_accounts()
      if 'NextToken' in accounts:
      nexttoken=accounts['NextToken']
      else:
      moreAccounts=False
      for account in accounts['Accounts']:
      if account['Status'] != 'SUSPENDED' and account['Status'] != 'CLOSED' :
      account_id = account['Id']
      accountList.append(account_id)


      print(accountList)

      def trigger_sfn():
      ssm = boto3.client('ssm')
      role_arn = "arn:aws:iam::xxxxxxxx:role/execute-sfn"
      region_name = "us-east-1"

      ami_id = ssm.get_parameter(Name='/BaseAMI/newest')['Parameter']['Value']
      print(ami_id)

      token = get_sts_token(RoleArn=role_arn, RegionName=region_name)
      print(token)

      access_key = token['AccessKeyId']
      secret_key = token['SecretAccessKey']
      session_token = token['SessionToken']

      sfn = boto3.client('stepfunctions',
      aws_access_key_id=access_key,
      aws_secret_access_key=secret_key,
      aws_session_token=session_token)

      response = sfn.start_execution(
      stateMachineArn='arn:aws:states:us-east-1:xxxxxxxx:stateMachine:ami-share',
      input=""ami_id": ami_id, "source_account_id": "112233445566", "accountList": accountList, "kms_key_arn": "alias/aws/ebs""
      )

      print(response)


      TRACE:



      An error occurred (InvalidExecutionInput) when calling the 
      StartExecution operation: Invalid State Machine Execution Input:
      'com.fasterxml.jackson.core.JsonParseException: Unrecognized token
      'ami_id': was expecting ('true', 'false' or 'null')
      at [Source: (String)""ami_id": ami_id, "source_account_id":
      "112233445566", "accountList": accountList, "kms_key_arn":
      "alias/aws/ebs""; line: 1, column: 18]': InvalidExecutionInput
      Traceback (most recent call last):
      File "/var/task/lambda_function.py", line 6, in lambda_handler
      trigger_sfn()
      File "/var/task/lambda_function.py", line 96, in trigger_sfn
      input=""ami_id": ami_id, "source_account_id": "112233445566",
      "accountList": accountList, "kms_key_arn": "alias/aws/ebs""
      File "/var/runtime/botocore/client.py", line 314, in _api_call
      return self._make_api_call(operation_name, kwargs)
      File "/var/runtime/botocore/client.py", line 612, in _make_api_call
      raise error_class(parsed_response, operation_name)
      botocore.errorfactory.InvalidExecutionInput: An error occurred
      (InvalidExecutionInput) when calling the StartExecution operation:
      Invalid State Machine Execution Input:
      'com.fasterxml.jackson.core.JsonParseException: Unrecognized token
      'ami_id': was expecting ('true', 'false' or 'null')
      at [Source: (String)""ami_id": ami_id, "source_account_id":
      "112233445566", "accountList": accountList, "kms_key_arn":
      "alias/aws/ebs""; line: 1, column: 18]'






      json python-3.x amazon-web-services boto3 aws-step-functions






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 14:49







      dmn0972

















      asked Mar 27 at 14:40









      dmn0972dmn0972

      946 bronze badges




      946 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can add the value of the variable to the string like this:



          input=""ami_id": "" + ami_id + "", "source_account_id": "112233445566", "accountList": accountList, "kms_key_arn": "alias/aws/ebs""


          Your code currently sends the literal string "ami_id", instead of the variable value of ami_id






          share|improve this answer



























          • This worked after testing. Is there any documentation you have on json variables?

            – dmn0972
            Mar 27 at 15:34






          • 1





            This might help you, it shows how you can turn the JSON into a string using .dump function. The approach you have right now is writing the JSON in string format from the start, which is why it works when we add the ami_id string to the rest of the string. If you want to make it neater, you could form the JSON using json.dumps

            – Deiv
            Mar 27 at 15:39











          • OK, so the output is now failing again because there are no quotes around the ami_id value. Is there a way I can pass the variable and add quotes around it, too?

            – dmn0972
            Mar 27 at 16:02






          • 1





            Yupe, I edited my answer, as it should technically be with quotes

            – Deiv
            Mar 27 at 16:25










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379944%2fpass-variable-into-step-function-start-execution-input-parameter%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can add the value of the variable to the string like this:



          input=""ami_id": "" + ami_id + "", "source_account_id": "112233445566", "accountList": accountList, "kms_key_arn": "alias/aws/ebs""


          Your code currently sends the literal string "ami_id", instead of the variable value of ami_id






          share|improve this answer



























          • This worked after testing. Is there any documentation you have on json variables?

            – dmn0972
            Mar 27 at 15:34






          • 1





            This might help you, it shows how you can turn the JSON into a string using .dump function. The approach you have right now is writing the JSON in string format from the start, which is why it works when we add the ami_id string to the rest of the string. If you want to make it neater, you could form the JSON using json.dumps

            – Deiv
            Mar 27 at 15:39











          • OK, so the output is now failing again because there are no quotes around the ami_id value. Is there a way I can pass the variable and add quotes around it, too?

            – dmn0972
            Mar 27 at 16:02






          • 1





            Yupe, I edited my answer, as it should technically be with quotes

            – Deiv
            Mar 27 at 16:25















          1














          You can add the value of the variable to the string like this:



          input=""ami_id": "" + ami_id + "", "source_account_id": "112233445566", "accountList": accountList, "kms_key_arn": "alias/aws/ebs""


          Your code currently sends the literal string "ami_id", instead of the variable value of ami_id






          share|improve this answer



























          • This worked after testing. Is there any documentation you have on json variables?

            – dmn0972
            Mar 27 at 15:34






          • 1





            This might help you, it shows how you can turn the JSON into a string using .dump function. The approach you have right now is writing the JSON in string format from the start, which is why it works when we add the ami_id string to the rest of the string. If you want to make it neater, you could form the JSON using json.dumps

            – Deiv
            Mar 27 at 15:39











          • OK, so the output is now failing again because there are no quotes around the ami_id value. Is there a way I can pass the variable and add quotes around it, too?

            – dmn0972
            Mar 27 at 16:02






          • 1





            Yupe, I edited my answer, as it should technically be with quotes

            – Deiv
            Mar 27 at 16:25













          1












          1








          1







          You can add the value of the variable to the string like this:



          input=""ami_id": "" + ami_id + "", "source_account_id": "112233445566", "accountList": accountList, "kms_key_arn": "alias/aws/ebs""


          Your code currently sends the literal string "ami_id", instead of the variable value of ami_id






          share|improve this answer















          You can add the value of the variable to the string like this:



          input=""ami_id": "" + ami_id + "", "source_account_id": "112233445566", "accountList": accountList, "kms_key_arn": "alias/aws/ebs""


          Your code currently sends the literal string "ami_id", instead of the variable value of ami_id







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 27 at 16:24

























          answered Mar 27 at 15:06









          DeivDeiv

          1,6052 gold badges9 silver badges18 bronze badges




          1,6052 gold badges9 silver badges18 bronze badges















          • This worked after testing. Is there any documentation you have on json variables?

            – dmn0972
            Mar 27 at 15:34






          • 1





            This might help you, it shows how you can turn the JSON into a string using .dump function. The approach you have right now is writing the JSON in string format from the start, which is why it works when we add the ami_id string to the rest of the string. If you want to make it neater, you could form the JSON using json.dumps

            – Deiv
            Mar 27 at 15:39











          • OK, so the output is now failing again because there are no quotes around the ami_id value. Is there a way I can pass the variable and add quotes around it, too?

            – dmn0972
            Mar 27 at 16:02






          • 1





            Yupe, I edited my answer, as it should technically be with quotes

            – Deiv
            Mar 27 at 16:25

















          • This worked after testing. Is there any documentation you have on json variables?

            – dmn0972
            Mar 27 at 15:34






          • 1





            This might help you, it shows how you can turn the JSON into a string using .dump function. The approach you have right now is writing the JSON in string format from the start, which is why it works when we add the ami_id string to the rest of the string. If you want to make it neater, you could form the JSON using json.dumps

            – Deiv
            Mar 27 at 15:39











          • OK, so the output is now failing again because there are no quotes around the ami_id value. Is there a way I can pass the variable and add quotes around it, too?

            – dmn0972
            Mar 27 at 16:02






          • 1





            Yupe, I edited my answer, as it should technically be with quotes

            – Deiv
            Mar 27 at 16:25
















          This worked after testing. Is there any documentation you have on json variables?

          – dmn0972
          Mar 27 at 15:34





          This worked after testing. Is there any documentation you have on json variables?

          – dmn0972
          Mar 27 at 15:34




          1




          1





          This might help you, it shows how you can turn the JSON into a string using .dump function. The approach you have right now is writing the JSON in string format from the start, which is why it works when we add the ami_id string to the rest of the string. If you want to make it neater, you could form the JSON using json.dumps

          – Deiv
          Mar 27 at 15:39





          This might help you, it shows how you can turn the JSON into a string using .dump function. The approach you have right now is writing the JSON in string format from the start, which is why it works when we add the ami_id string to the rest of the string. If you want to make it neater, you could form the JSON using json.dumps

          – Deiv
          Mar 27 at 15:39













          OK, so the output is now failing again because there are no quotes around the ami_id value. Is there a way I can pass the variable and add quotes around it, too?

          – dmn0972
          Mar 27 at 16:02





          OK, so the output is now failing again because there are no quotes around the ami_id value. Is there a way I can pass the variable and add quotes around it, too?

          – dmn0972
          Mar 27 at 16:02




          1




          1





          Yupe, I edited my answer, as it should technically be with quotes

          – Deiv
          Mar 27 at 16:25





          Yupe, I edited my answer, as it should technically be with quotes

          – Deiv
          Mar 27 at 16:25








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379944%2fpass-variable-into-step-function-start-execution-input-parameter%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript