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

(aws-stepfunctions): L3 Construct for API Gateway HTTP/REST Api Backed by Step Functions #15081

Closed
1 of 2 tasks
diegotry opened this issue Jun 11, 2021 · 14 comments · Fixed by #16827
Closed
1 of 2 tasks
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions effort/large Large work item – several weeks of effort feature/pattern Feature requests related to high level L3 pattern libraries feature-request A feature should be added or improved. needs-discussion This issue/PR requires more discussion with community. p1

Comments

@diegotry
Copy link
Contributor

diegotry commented Jun 11, 2021

As a CDK user, I'd like to have a simpler way to create an API Gateway (either REST or HTTP) with Step Functions Synchronous Workflows. The new construct will be responsible for creating the API Gateway resources, connecting it to a Step Functions State Machine with the necessary permissions and predefined features.

Use Case

I want to build APIs that are handled by Step Functions as my API orchestrator. The integration with Synchronous workflows was recently launched:

https://aws.amazon.com/about-aws/whats-new/2021/05/amazon-api-gateway-rest-apis-integrates-with-step-funtions-synchronous-express-workflows/ and I want to leverage the infrastructure to CDK.

Proposed Solution

  1. StepFunctionsHttpApi
  • Backed by API Gateway HTTP API
  1. StepFunctionsRestApi
  • Backed by API Gateway REST API

Convention over configuration
Convention over configuration (also known as coding by convention) is a software design paradigm used by software frameworks that attempts to decrease the number of decisions that a developer using the framework is required to make without necessarily losing flexibility.

Convention #1: By default, the Output transformation should return only the Execution Output. If possible, I'd like to have:

HTTP 200: Execution succeeded
HTTP 400: Execution completed, but it failed for some execution-level reason. Example: a validation step. These are for known errors.
HTTP 500: Step Functions failure (server-side, not execution level)

Convention #2: The request body is mapped to the execution input.
Convention #3: All logs from Step Functions are enabled by default
Convention #4: X-Ray is enabled on Step Functions State Machine

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@diegotry diegotry added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 11, 2021
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Jun 11, 2021
@github-actions github-actions bot added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Jun 11, 2021
@BenChaimberg
Copy link
Contributor

Thank you for your feature request! This seems like a great pattern for customers, but would not really belong in this library as it is fairly abstract (an L3, as you point out). Check out awslabs/aws-solutions-constructs#145 for a better place, maybe you can help the design and implementation effort over there!

@BenChaimberg BenChaimberg added closing-soon This issue will automatically close in 4 days unless further comments are made. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 11, 2021
@BenChaimberg
Copy link
Contributor

Actually, on a further look, this may be a good fit for aws-apigatewayv2-integrations. What do you think, @nija-at?

@BenChaimberg BenChaimberg added the @aws-cdk/aws-apigatewayv2-integrations Related to AWS APIGatewayv2 Integrations label Jun 11, 2021
@diegotry
Copy link
Contributor Author

I believe we may offer two types of integrations - or maybe more. My intention is to use Synchronous Workflows from AWS Step Functions and not the standard workflows, which is asynchronous.

HTTP APIs -> Synchronous Workflows (cheaper and potentially faster), but without all the features from REST APIs.
REST APIs -> Synchronous Workflows (has input/output transformation, but it is more expensive at scale).

@nija-at
Copy link
Contributor

nija-at commented Jun 11, 2021

From a basic read of this issue, @BenChaimberg is right. This does not have to be an L3. It just needs to an aws service integration pattern.

We are tracking this already here - #11947.

Let me know if there are other reasons why being L3 would be advantageous.

@nija-at nija-at removed their assignment Jun 11, 2021
@BenChaimberg
Copy link
Contributor

Closing in favour of the already open issue, any further discussion of the integration should be located there. Discussion of a possible L3 should occur in the solutions constructs issue mentioned above.

@BenChaimberg BenChaimberg added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 11, 2021
@diegotry
Copy link
Contributor Author

diegotry commented Jun 11, 2021

Correct me if I'm wrong.

Integration pattern works for API-GW V2 (which is HTTP APIs product). The Step Functions integration with HTTP APIs needs a similar version of https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigatewayv2-integrations.LambdaProxyIntegration.html which is for Lambda.

For API-GW V1 (a.k.a. REST APIs) the integration is a bit different. This is the corresponding for Lambda: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.LambdaRestApi.html

For AWS Services, there is no corresponding one. We can make use of:

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.AwsIntegration.html

For HTTP APIs with Step Functions, it returns all the fields from the API. It includes ARNs (state machine ARN and execution ARN), therefore the Account Id is also returned. If I am offering this API to end customers, I don't want them to have access to those informations. Currently, with HTTP APIs is not possible to apply output transformation.

Rest APIs has more features than HTTP APIs, but it costs more. It is possible to remove all the metadata information and return only the execution output to the caller.

I believe we can have another layer of abstraction that makes it even easier for users. For Step Functions, let's say I want to build an API that is backed by Step Functions. Let's call it Serverless/Workflow APIs. In the end, what I want is a public endpoint for my state machine where I can make HTTP requests and start new executions.

The way I understand (For Step Functions):

L1: Raw CloudFormation resources.
L2: Makes it eiaser to create resources by taking care of IAM permissions and so on.

The next abstraction level/use case that I'd like to have is the API-GW that connects to a State Machine. I don't want to manage in my code an integration proxy (what does it even mean? Will I ever have to change this after it is connected?). I just want an endpoint for my state machine.

The convention over configuration approach that I mentioned is related to the default values. For expert users, they can modify the props of each resource to achieve what they want (lower level of logs, different log group, disable xray, manipulate input/output transformation, etc). It can be as simple as providing a state machine definition, a name and the execution role.

My proposal is:

Add L2 constructs to match what API-Gateway has in the console (Lambda, AWS Service, ..). We can have AwsServiceIntegrationRestApi. Step Functions can build on top of that.

Another option is to build constructs for Step Functions with API Gateway resources and the link between them. I think this makes sense to belong on aws-solutions-constructs.

@ibrahimcesar
Copy link
Contributor

I was working in integrating API Gateway HTTP with Synchronous Express Workflows and this proposal is exactly "the missing link". I think these abstractions baked-in would be a huge leap for a better understanding (and use) of the potential Step Functions have. A perfect fit for checkout-like workflows to anyone using CDK.

@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Jun 11, 2021
@mariobittencourt
Copy link

Hi there, I am a bit confused about the current state of this issue. Will we have a v2 integration - like the lambdaproxy - for the API gateway so it enables us to startExecution/startSyncExecution of step functions without an in-between lambda?

@nija-at
Copy link
Contributor

nija-at commented Jun 14, 2021

@diegotry - I'm not able to follow all of your arguments or statements in your comment. Let me try and respond to the ones I did.
I'm also not very familiar with all of the various integrations available, so bear with me if I'm missing the obvious.

Add L2 constructs to match what API-Gateway has in the console (Lambda, AWS Service, ..). We can have AwsServiceIntegrationRestApi. Step Functions can build on top of that.

We should aim to also build the specific integrations in the AWS CDK. We could have a generic interface for AWS services that are not yet implemented in the AWS CDK.
We have precedence for this. stepfunctions-tasks contains integrates step functions with specific AWS services and apigatewayv2-integrations contains integrates HTTP API with Lambda, ALB, NLB, etc.

In the end, what I want is a public endpoint for my state machine where I can make HTTP requests and start new executions.

This one is on the line. It could be similar to the LambdaRestApi construct and land in the AWS CDK.
However, I don't have a good home for it in the AWS CDK at the moment, so it's best, to keep it with the solutions construct (if they'll accept it).

For HTTP APIs with Step Functions, it returns all the fields from the API. It includes ARNs (state machine ARN and execution ARN), therefore the Account Id is also returned. If I am offering this API to end customers, I don't want them to have access to those informations

Not clear what you're saying here. What returns all the fields and why is it bad?


If you're interested in the implementation, before you work on a pull request, I will say that this work needs to start with some initial design. It would be very helpful by providing the CDK user experience of integrating HTTP API or Rest API with Step Functions.
That way, we can iron out the interfaces and APIs before you get too deep into the implementation.

I would also start with small changes, adding the layers required one by one, rather than a large pull request attempting to make all of these changes.

@diegotry
Copy link
Contributor Author

What returns all the fields and why is it bad?

Let's say I have a website that sends a request to API-GW HTTP APIs. Behind the API I have a Step Functions workflow. As a user, all I want from the workflow is the output, not all the fields that are returned in the StartSyncExecution API.

HTTP APIs returns all the response from the service it integrates. Rest APIs has a feature to manipulate the API output, so in this case, I can return only the workflow output.

From my understanding, apigatewayv2-integrations has HTTP APIs integrations. The integrations are already defined and it will probably fail during creation if I try to use something that doesn't exist. If I go to the AWS console, this is what I see when I try to create an HTTP API with Step Functions integration:

Screen Shot 2021-06-14 at 9 02 11 AM

On the other hand, REST APIs has an open text field that I believe it will succeed during creation and fail during the request (Unknown Operation or something). This is what I see in the console (please see that I selected AWS Service):

Screen Shot 2021-06-14 at 9 07 05 AM

I believe we need to make it easier for the AWS Service Integration for Rest API. AwsServiceIntegrationRestApi can be the pair of LambdaRestApi. Please note they are in the apigateway-v1 and not apigateway-v2.

My suggestion is that we start with AwsServiceIntegrationRestApi that allows any integration from Rest API to AWS Services. This is probably possible through AwsIntegration but this class does not give me a well-contructed endpoint in the end, it looks more like the glue between the services.

After we have the AwsServiceIntegrationRestApi available, we can build StepFunctionsRestApi that uses AwsServiceIntegrationRestApi.

Later, we can build something for apigatewayv2-integrations which integrates with HTTP APIs.

@BenChaimberg BenChaimberg removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 16, 2021
@BenChaimberg
Copy link
Contributor

Thank you for your clarifications – I think we've come to a better understanding of what you're proposing! This seems to be an API Gateway feature that allows proxy integration with an AWS service (maybe AwsRestApi). Then, we will have a StepFunctionsRestApi subclass that adds some stricter typing and default transformations to pare down to just a response body. My concern here is that the number of services that can actually handle a proxy-style integration is quite small, as the whole point of AwsRestApi is for every route and method to be handled by the service (otherwise, AwsIntegration is the way to go). Do you have an idea for other services that would fall into this pattern?

@diegotry
Copy link
Contributor Author

My concern here is that the number of services that can actually handle a proxy-style integration is quite small

Not sure I understood your point here. API-GW RestApi offers integration with 100+ services.

Screen Shot 2021-06-16 at 6 40 41 PM

Whoever is creating the API should specify what HTTP Method they want and what AWS Operation they want to match. (ex: HTTP POST -> .).

I think the current structure for creating the AWS Service Integration can be simpler and less error-prone if we have well defined structures. Let me spend some time thinking about what the new structure would look like and I will get back to this request.

I agree those should be part of the apigateway module.

@BenChaimberg
Copy link
Contributor

Unassigning myself for now, please @mention me when you have made updates

@BenChaimberg BenChaimberg removed their assignment Jul 21, 2021
@BenChaimberg BenChaimberg added the needs-discussion This issue/PR requires more discussion with community. label Jul 21, 2021
@peterwoodworth peterwoodworth added feature/pattern Feature requests related to high level L3 pattern libraries p1 labels Jul 22, 2021
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Sep 21, 2021
…nual deployment. It is working as expected on the console.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Sep 21, 2021
…nual deployment. It is working as expected on the console.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 4, 2021
…ntegration testing not tested yet.

Rebased branch with master.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 4, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 4, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 6, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 6, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 7, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 7, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 7, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 13, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 13, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 14, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
Added code snippet to the README.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 14, 2021
…ing.

Fixed Integration test and generated expected json for stepFunctionsRestApi Stack deployment.
Added code snippet to the README.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 18, 2021
…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.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 20, 2021
…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.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 21, 2021
…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.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 21, 2021
…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.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 21, 2021
…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.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 23, 2021
…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.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 26, 2021
…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.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Oct 26, 2021
…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.
closes aws#15081.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Nov 1, 2021
…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.
saqibdhuka pushed a commit to saqibdhuka/aws-cdk that referenced this issue Nov 1, 2021
…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.
@mergify mergify bot closed this as completed in #16827 Nov 25, 2021
mergify bot pushed a commit that referenced this issue Nov 25, 2021
- Added StepFunctionsRestApi and StepFunctionsIntegration implementation

closes #15081.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

beezly pushed a commit to beezly/aws-cdk that referenced this issue Nov 29, 2021
- Added StepFunctionsRestApi and StepFunctionsIntegration implementation

closes aws#15081.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
- Added StepFunctionsRestApi and StepFunctionsIntegration implementation

closes aws#15081.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions effort/large Large work item – several weeks of effort feature/pattern Feature requests related to high level L3 pattern libraries feature-request A feature should be added or improved. needs-discussion This issue/PR requires more discussion with community. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants