Skip to content

Commit

Permalink
Merge branch 'main' into scanlonp/merit-badger-update
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 21, 2022
2 parents 92dcbbd + fbb941f commit 693c83a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions-tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ const listBuckets = new tasks.CallAwsService(this, 'ListBuckets', {
});
```

Use the `additionalIamStatements` prop to pass additional IAM statements that will be added to the
state machine role's policy. Use it in the case where the call requires more than a single statement
to be executed:

```ts
const detectLabels = new tasks.CallAwsService(stack, 'DetectLabels', {
service: 'rekognition',
action: 'detectLabels',
iamResources: ['*'],
additionalIamStatements: [
new iam.PolicyStatement({
actions: ['s3:getObject'],
resources: ['arn:aws:s3:::my-bucket/*'],
}),
],
});
```

## Athena

Step Functions supports [Athena](https://docs.aws.amazon.com/step-functions/latest/dg/connect-athena.html) through the service integration pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ export interface CallAwsServiceProps extends sfn.TaskStateBaseProps {
* @default - service:action
*/
readonly iamAction?: string;

/**
* Additional IAM statements that will be added to the state machine
* role's policy.
*
* Use in the case where the call requires more than a single statement to
* be executed, e.g. `rekognition:detectLabels` requires also S3 permissions
* to read the object on which it must act.
*
* @default - no additional statements are added
*/
readonly additionalIamStatements?: iam.PolicyStatement[];
}

/**
Expand All @@ -75,6 +87,7 @@ export class CallAwsService extends sfn.TaskStateBase {
// https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_action.html
actions: [props.iamAction ?? `${props.service}:${props.action}`],
}),
...props.additionalIamStatements ?? [],
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Template } from '@aws-cdk/assertions';
import * as iam from '@aws-cdk/aws-iam';
import * as sfn from '@aws-cdk/aws-stepfunctions';
import * as cdk from '@aws-cdk/core';
import * as tasks from '../../lib';
Expand Down Expand Up @@ -159,3 +160,41 @@ test('throws with invalid integration pattern', () => {
iamResources: ['*'],
})).toThrow(/The RUN_JOB integration pattern is not supported for CallAwsService/);
});

test('can pass additional IAM statements', () => {
// WHEN
const task = new tasks.CallAwsService(stack, 'DetectLabels', {
service: 'rekognition',
action: 'detectLabels',
iamResources: ['*'],
additionalIamStatements: [
new iam.PolicyStatement({
actions: ['s3:getObject'],
resources: ['arn:aws:s3:::my-bucket/*'],
}),
],
});

new sfn.StateMachine(stack, 'StateMachine', {
definition: task,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Action: 'rekognition:detectLabels',
Effect: 'Allow',
Resource: '*',
},
{
Action: 's3:getObject',
Effect: 'Allow',
Resource: 'arn:aws:s3:::my-bucket/*',
},
],
Version: '2012-10-17',
},
});
});

0 comments on commit 693c83a

Please sign in to comment.