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

feat(stepfunctions-tasks): describe dynamo import/export tasks #27711

Closed
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 28 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aw
- [PutItem](#putitem)
- [DeleteItem](#deleteitem)
- [UpdateItem](#updateitem)
- [DescribeExport](#describeexport)
- [DescribeImport](#describeimport)
- [ECS](#ecs)
- [RunTask](#runtask)
- [EC2](#ec2)
Expand Down Expand Up @@ -452,6 +454,32 @@ new tasks.DynamoUpdateItem(this, 'UpdateItem', {
});
```

### DescribeExport

The [DescribeExport](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeExport.html) operation
describes an existing table export.

```ts
declare const myTable: dynamodb.Table;
new tasks.DynamoDescribeExport(stack, 'DescribeExport', {
table,
exportArn: sfn.JsonPath.stringAt('$.ExportDescription.ExportArn'),
});
```

### DescribeImport

The [DescribeImport](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeImport.html) operation
represents the properties of the import.

```ts
declare const myTable: dynamodb.Table;
new tasks.DynamoDescribeImport(stack, 'DescribeImport', {
table,
importArn: sfn.JsonPath.stringAt('$.ImportDescription.ImportArn'),
});
```

## ECS

Step Functions supports [ECS/Fargate](https://docs.aws.amazon.com/step-functions/latest/dg/connect-ecs.html) through the service integration pattern.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Construct } from 'constructs';
import { getDynamoResourceArnFromApi } from './private/utils';
import * as ddb from '../../../aws-dynamodb';
import * as iam from '../../../aws-iam';
import * as sfn from '../../../aws-stepfunctions';
import { Stack } from '../../../core';

/**
* Properties for DynamoDescribeExport Task
*/
export interface DynamoDescribeExportProps extends sfn.TaskStateBaseProps {
/**
* The name of the table where the export was created.
*/
readonly table: ddb.ITable;
/**
* The Amazon Resource Name (ARN) associated with the export.
*
* @see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeExport.html#API_DescribeExport_RequestSyntax
*/
readonly exportArn: string;
}

/**
* A StepFunctions task to call DynamoDescribeExport
*/
export class DynamoDescribeExport extends sfn.TaskStateBase {
protected readonly taskMetrics?: sfn.TaskMetricsConfig;
protected readonly taskPolicies?: iam.PolicyStatement[];

constructor(scope: Construct, id: string, private readonly props: DynamoDescribeExportProps) {
super(scope, id, props);

this.taskPolicies = [
new iam.PolicyStatement({
resources: [
Stack.of(this).formatArn({
service: 'dynamodb',
resource: 'table',
resourceName: `${props.table.tableName}/export/*`,
}),
],
actions: ['dynamodb:DescribeExport'],
}),
];
}

/**
* @internal
*/
protected _renderTask(): any {
return {
Resource: getDynamoResourceArnFromApi('describeExport'),
Parameters: sfn.FieldUtils.renderObject({
ExportArn: this.props.exportArn,
}),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Construct } from 'constructs';
import { getDynamoResourceArnFromApi } from './private/utils';
import * as ddb from '../../../aws-dynamodb';
import * as iam from '../../../aws-iam';
import * as sfn from '../../../aws-stepfunctions';
import { Stack } from '../../../core';

/**
* Properties for DynamoDescribeImport Task
*/
export interface DynamoDescribeImportProps extends sfn.TaskStateBaseProps {
/**
* The name of the table where the import was created.
*/
readonly table: ddb.ITable;
/**
* The Amazon Resource Name (ARN) associated with the table you're importing to.
*
* @see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeImport.html#API_DescribeImport_RequestSyntax
*/
readonly importArn: string;
}

/**
* A StepFunctions task to call DynamoDescribeImport
*/
export class DynamoDescribeImport extends sfn.TaskStateBase {
protected readonly taskMetrics?: sfn.TaskMetricsConfig;
protected readonly taskPolicies?: iam.PolicyStatement[];

constructor(scope: Construct, id: string, private readonly props: DynamoDescribeImportProps) {
super(scope, id, props);

this.taskPolicies = [
new iam.PolicyStatement({
resources: [
Stack.of(this).formatArn({
service: 'dynamodb',
resource: 'table',
resourceName: `${props.table.tableName}/import/*`,
}),
],
actions: ['dynamodb:DescribeImport'],
}),
];
}

/**
* @internal
*/
protected _renderTask(): any {
return {
Resource: getDynamoResourceArnFromApi('describeImport'),
Parameters: sfn.FieldUtils.renderObject({
ImportArn: this.props.importArn,
}),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function getDynamoResourceArn(method: DynamoMethod) {
return integrationResourceArn('dynamodb', `${method.toLowerCase()}Item`, sfn.IntegrationPattern.REQUEST_RESPONSE);
}

export function getDynamoResourceArnFromApi(api: string) {
return integrationResourceArn('dynamodb', api, sfn.IntegrationPattern.REQUEST_RESPONSE);
}

export function transformAttributeValueMap(attrMap?: { [key: string]: DynamoAttributeValue }) {
const transformedValue: any = {};
for (const key in attrMap) {
Expand Down
2 changes: 2 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export * from './dynamodb/put-item';
export * from './dynamodb/update-item';
export * from './dynamodb/delete-item';
export * from './dynamodb/shared-types';
export * from './dynamodb/describe-export';
export * from './dynamodb/describe-import';
export * from './codebuild/start-build';
export * from './athena/start-query-execution';
export * from './athena/stop-query-execution';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as ddb from '../../../aws-dynamodb';
import * as cdk from '../../../core';
import * as tasks from '../../lib';

let stack: cdk.Stack;
let table: ddb.Table;

beforeEach(() => {
stack = new cdk.Stack();
table = new ddb.Table(stack, 'MyTable', {
tableName: 'MyTable',
partitionKey: {
name: 'id',
type: ddb.AttributeType.STRING,
},
});
});

test('DescribeExport task', () => {
const task = new tasks.DynamoDescribeExport(stack, 'DescribeExport', {
table,
exportArn: 'arn:aws:dynamodb:eu-south-1:123456789012:table/MyTable/export/1234567890123-abcdef',
});

expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':states:::dynamodb:describeExport',
],
],
},
End: true,
Parameters: {
ExportArn: 'arn:aws:dynamodb:eu-south-1:123456789012:table/MyTable/export/1234567890123-abcdef',
},
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as ddb from '../../../aws-dynamodb';
import * as cdk from '../../../core';
import * as tasks from '../../lib';

let stack: cdk.Stack;
let table: ddb.Table;

beforeEach(() => {
stack = new cdk.Stack();
table = new ddb.Table(stack, 'MyTable', {
tableName: 'MyTable',
partitionKey: {
name: 'id',
type: ddb.AttributeType.STRING,
},
});
});

test('DescribeImport task', () => {
const task = new tasks.DynamoDescribeImport(stack, 'DescribeImport', {
table,
importArn: 'arn:aws:dynamodb:eu-south-1:123456789012:table/MyTable/import/1234567890123-abcdef',
});

expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':states:::dynamodb:describeImport',
],
],
},
End: true,
Parameters: {
ImportArn: 'arn:aws:dynamodb:eu-south-1:123456789012:table/MyTable/import/1234567890123-abcdef',
},
});
});
Loading