Sub topic 6
Calling AWS services directly
This chapter assumes you can read a basic state machine definition and know how a Task state uses Resource and Parameters. It also assumes you know what an IAM execution role is. The aim is to call AWS services from a workflow without writing a Lambda function as glue.
Why skip the Lambda function
A common first design puts a Lambda function in every Task state, and that function calls one AWS API. This costs you code to maintain, a runtime to patch, and extra invocation charges. Step Functions can call many services itself, so the Task state sends the request and receives the response.
A service integration is a Task state whose Resource names a service API instead of a function. There are two kinds.
Optimized integrations
Optimized integrations are built for Step Functions for a limited set of services, such as Lambda, SNS, SQS, DynamoDB, ECS, and Glue. They use a Resource of this form:
arn:aws:states:::sns:publishStep Functions shapes the request and response for you. For example, the Lambda integration wraps the function's return value under a Payload key, which is why the earlier example used ResultSelector to read $.Payload.
AWS SDK integrations
AWS SDK integrations expose most API actions of most AWS services. The Resource has this form:
arn:aws:states:::aws-sdk:<service>:<apiAction>The service name is lowercase and the action is in camelCase, for example aws-sdk:dynamodb:putItem. The Parameters field follows the API's own request shape, so keys are in PascalCase, matching the API reference.
This state writes an order to DynamoDB with no Lambda function:
{
"StartAt": "SaveOrder",
"States": {
"SaveOrder": {
"Type": "Task",
"Resource": "arn:aws:states:::aws-sdk:dynamodb:putItem",
"Parameters": {
"TableName": "Orders",
"Item": {
"OrderId": { "S.$": "$.orderId" },
"Status": { "S": "RECEIVED" }
}
},
"ResultPath": null,
"End": true
}
}
}Two details matter here. The .$ suffix on S.$ tells Step Functions to read the value from the state input. ResultPath set to null discards the API response, so the state passes its original input through unchanged.
Choosing between them
| Question | Optimized | AWS SDK |
|---|---|---|
| Service coverage | A limited set | Most services and actions |
| Request and response shape | Adjusted by Step Functions | Matches the service API |
| Supports `.sync` and `.waitForTaskToken` | For many services | Only `.waitForTaskToken` |
Use an optimized integration when one exists for your action, because its input and output are simpler. Use the SDK integration when the action is not covered, such as aws-sdk:s3:listObjectsV2 or aws-sdk:ssm:getParameter. Use Lambda only when you need custom logic, such as transforming data or calling a non-AWS API.
Common errors
- Access denied. The execution role needs the IAM action for the call, for example
dynamodb:PutItem. Step Functions does not grant it for you. The next chapters on IAM cover this in detail. - Wrong parameter casing. SDK integrations expect
TableName, nottableName. A casing mistake typically fails at runtime with a validation error from the target service. - Wrong error names in Retry or Catch. SDK integrations report errors as
<Service>.<ErrorCode>, for exampleDynamoDb.ConditionalCheckFailedException. UsingStates.ALLis a safe fallback. - Forgetting the response. The response is placed in the state output only if you allow it. Use
ResultSelectorto trim it andResultPathto merge it with the input.
Exercise
You need a state to read a parameter from Systems Manager Parameter Store, and no optimized integration exists for it. Which Resource value do you use, and what does the execution role need?
Show answer
Use arn:aws:states:::aws-sdk:ssm:getParameter with Name in Parameters. The execution role needs the ssm:GetParameter permission on the parameter's ARN.