Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stepfunctions-tasks): jobQueueArn support JsonPath or JSONata #33670

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(stepfunctions-tasks): IAM policy use wildcard for JsonPath or JSO…
…Nata
  • Loading branch information
phuhung273 committed Mar 2, 2025
commit db1fec601af271b8be1697cfd415cefeaa3ccef2
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import * as ec2 from '../../../aws-ec2';
import * as iam from '../../../aws-iam';
import * as sfn from '../../../aws-stepfunctions';
import { Size, Stack, withResolved } from '../../../core';
import { integrationResourceArn, validatePatternSupported } from '../private/task-utils';
import { integrationResourceArn, isJsonPathOrJsonataExpression, validatePatternSupported } from '../private/task-utils';

/**
* The overrides that should be sent to a container.
@@ -311,7 +311,7 @@ export class BatchSubmitJob extends sfn.TaskStateBase {
// Using the alternative permissions as mentioned here:
// https://docs.aws.amazon.com/batch/latest/userguide/batch-supported-iam-actions-resources.html
new iam.PolicyStatement({
resources: [
resources: isJsonPathOrJsonataExpression(this.props.jobQueueArn) ? ['*'] : [
Stack.of(this).formatArn({
service: 'batch',
resource: 'job-definition',
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import * as ecs from '../../../aws-ecs';
import * as sfn from '../../../aws-stepfunctions';
import { BatchSubmitJob } from '../../../aws-stepfunctions-tasks';
import * as cdk from '../../../core';
import { Template } from '../../../assertions';

let stack: cdk.Stack;
let batchJobDefinition: batch.IJobDefinition;
@@ -512,3 +513,80 @@ test('throws if tags has invalid value', () => {
/Tag value maximum size is 256/,
);
});

test('supports passing jobQueueArn as JsonPath or JSONata', () => {
// WHEN
const task = new BatchSubmitJob(stack, 'Task', {
jobDefinitionArn: batchJobDefinition.jobDefinitionArn,
jobQueueArn: sfn.JsonPath.stringAt('$.jobQueueArn'),
jobName: sfn.JsonPath.stringAt('$.jobName'),
});

new sfn.StateMachine(stack, 'ParentStateMachine', {
definitionBody: sfn.DefinitionBody.fromChainable(task),
});

// THEN
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':states:::batch:submitJob.sync',
],
],
},
End: true,
Parameters: {
'JobDefinition': { Ref: 'JobDefinition24FFE3ED' },
'JobName.$': '$.jobName',
'JobQueue.$': '$.jobQueueArn'
},
});

Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Action: 'batch:SubmitJob',
Effect: 'Allow',
Resource: '*',
},
{
Action: [
'events:PutTargets',
'events:PutRule',
'events:DescribeRule'
],
Effect: 'Allow',
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':events:',
{
Ref: 'AWS::Region',
},
':',
{
Ref: 'AWS::AccountId',
},
':rule/StepFunctionsGetEventsForBatchJobsRule',
],
],
},
},
],
Version: '2012-10-17',
},
});
});
Loading
Oops, something went wrong.