Skip to content

Commit

Permalink
StepFunctionsRestApi implemented along with unit and integration test…
Browse files Browse the repository at this point in the history
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
Added code snippet to the README.
Removing restApiprops option as the composition in StepFunctionsRestApiProps.
Added Error for when state machine is not of type EXPRESS
Added Context to input with includeRequestContext boolean varibale to pass requestContext to State Machine input.
Created a builder class to make the long request template string more readable.
closes aws#15081.
  • Loading branch information
Saqib Dhuka committed Nov 1, 2021
1 parent e9a461d commit 014e130
Show file tree
Hide file tree
Showing 11 changed files with 2,062 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/@aws-cdk/aws-apigateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ running on AWS Lambda, or any web application.
- [Defining APIs](#defining-apis)
- [Breaking up Methods and Resources across Stacks](#breaking-up-methods-and-resources-across-stacks)
- [AWS Lambda-backed APIs](#aws-lambda-backed-apis)
- [AWS StepFunctions backed APIs](#aws-stepfunctions-backed-APIs)
- [Integration Targets](#integration-targets)
- [Usage Plan & API Keys](#usage-plan--api-keys)
- [Working with models](#working-with-models)
Expand Down Expand Up @@ -106,6 +107,31 @@ item.addMethod('GET'); // GET /items/{item}
item.addMethod('DELETE', new apigateway.HttpIntegration('http://amazon.com'));
```

## AWS StepFunctions backed APIs

You can use Amazon API Gateway with AWS Step Functions as the backend integration, specifically Synchronous Express Workflows.

The `StepFunctionsRestApi` construct makes this easy and also sets up input, output and error mapping. The `StepFunctionsRestApi` construct sets up the API Gateway REST API with an `ANY` HTTP method and sets up the api role with the required permission to invoke `StartSyncExecution` action on the AWS StepFunctions state machine. This will enable you to invoke any one of the API Gateway HTTP methods and get a response from the backend AWS StepFunctions state machine.

The following code defines a REST API that routes all requests to the specified AWS StepFunctions state machine:

```ts
const stateMachine = new stepFunctions.StateMachine(this, 'StateMachine', ...);
new apigateway.StepFunctionsRestApi(this, 'StepFunctionsRestApi', {
stateMachine: stateMachine,
});
```

You can add requestContext (similar to input requestContext from lambda input) to the input. The 'requestContext' parameter includes account ID, user identity, etc. that can be used by customers that want to know the identity of authorized users on the state machine side. The following code defines a REST API like above but also adds 'requestContext' to the input of the State Machine:

```ts
const stateMachine = new stepFunctions.StateMachine(this, 'StateMachine', ...);
new apigateway.StepFunctionsRestApi(this, 'StepFunctionsRestApi', {
stateMachine: stateMachine,
includeRequestContext: true,
});
```

### Breaking up Methods and Resources across Stacks

It is fairly common for REST APIs with a large number of Resources and Methods to hit the [CloudFormation
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-apigateway/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export * from './authorizers';
export * from './access-log';
export * from './api-definition';
export * from './gateway-response';
export * from './stepfunctions-api';

// AWS::ApiGateway CloudFormation Resources:
export * from './apigateway.generated';
Expand Down
Loading

0 comments on commit 014e130

Please sign in to comment.