Skip to content
v2.274.0

TaskRole Class ​

Role to be assumed by the State Machine's execution role for invoking a task's resource.

Example ​

ts
import * as lambda from 'aws-cdk-lib/aws-lambda';

declare const submitLambda: lambda.Function;
declare const iamRole: iam.Role;

// use a fixed role for all task invocations
const role = sfn.TaskRole.fromRole(iamRole);
// or use a json expression to resolve the role at runtime based on task inputs
//const role = sfn.TaskRole.fromRoleArnJsonPath('$.RoleArn');

const submitJob = new tasks.LambdaInvoke(this, 'Submit Job', {
  lambdaFunction: submitLambda,
  outputPath: '$.Payload',
  // use credentials
  credentials: { role },
});

Initializer ​

ts
new TaskRole()
python
TaskRole()
java
new TaskRole()
csharp
new TaskRole()
go
NewTaskRole()

Properties ​

resourcestringresourcestrresourceStringResourcestringResource*stringrequired#
Retrieves the resource for use in IAM Policies for this TaskRole.
roleArnstringrole_arnstrroleArnStringRoleArnstringRoleArn*stringrequired#
Retrieves the roleArn for this TaskRole.

Methods ​

fromRole(role: IRole): TaskRole // chainable@staticmethod def from_role(role: IRole) -> TaskRolepublic static TaskRole fromRole(IRole role)public static TaskRole FromRole(IRole role)func FromRole(Role IRole) TaskRolestatic#
Construct a task role based on the provided IAM Role.
1 parameter

Parameters

  • roleroleroleroleRole — IAM Role.
fromRoleArnJsonPath(expression: string): TaskRole // chainable@staticmethod def from_role_arn_json_path(expression: str) -> TaskRolepublic static TaskRole fromRoleArnJsonPath(String expression)public static TaskRole FromRoleArnJsonPath(string expression)func FromRoleArnJsonPath(Expression *string) TaskRolestatic#
Construct a task role retrieved from task inputs using a json expression.
1 parameter · example

Parameters

  • expressionexpressionexpressionexpressionExpression — json expression to roleArn.
ts
sfn.TaskRole.fromRoleArnJsonPath('$.RoleArn');