born to code
born to code

Reputation: 133

how to pass path parameter to AWS api gateway using AWS Step function?

In aws step function i need to call api gateway endpoint with path parameters from previous state values. enter image description here

Step Function Code (Api Gateway Call)

"API Gateway Request": {
  "Type": "Task",
  "Resource": "arn:aws:states:::apigateway:invoke",
  "Parameters": {
    "ApiEndpoint": "****.amazonaws.com",
    "Method": "GET",
    "Headers": {
      "Accept": [
        "application/json"
      ]
    },
    "Stage": "dev",
    "Path": "/sample/$.id",
    "AuthType": "IAM_ROLE"
  },
  "InputPath": "$.id",
  "Next": "Lambda Invoke",
  "ResultPath": "$.myStateInput"
}

Input to this state:

{ "id": "1231" }

Instead of replacing "$.id" as "1231", it just calling url like below enter image description here Api Gateway:

enter image description here

Please tell what i'm doing wrong ?

Upvotes: 5

Views: 1821

Answers (1)

Marcin
Marcin

Reputation: 238081

Based on the comments, the solution was to use intrinsic function:

"Path.$": States.Format('/sample/{}', $.id)

State Code

"API Gateway Request": {
  "Type": "Task",
  "Resource": "arn:aws:states:::apigateway:invoke",
  "Parameters": {
    "ApiEndpoint": "**.amazonaws.com",
    "Method": "GET",
    "Headers": {
      "Accept": [
        "application/json"
      ]
    },
    "Stage": "dev",
    "Path.$": "States.Format('/sample/{}', $.id)",
    "AuthType": "IAM_ROLE"
  },
  "Next": "Lambda Invoke",
  "ResultPath": "$.myStateInput"
}

Upvotes: 5

Related Questions