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

apigatewayv2: stateMachineArn does not fit schema for Operation: StepFunctions-StartSyncExecution #26328

Open
YishaqG opened this issue Jul 11, 2023 · 3 comments
Labels
@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 bug This issue is a bug. effort/medium Medium work item – several days of effort p3

Comments

@YishaqG
Copy link

YishaqG commented Jul 11, 2023

Describe the bug

I'm trying to create a ApiGatewayV2 route with AWS StepFunction integration. For this I'm using the L1 constructs but getting the following error message:

UPDATE_ROLLBACK_COMPLETE: Parameter: stateMachineArn does not fit schema for Operation: StepFunctions-StartSyncExecution. (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException

Expected Behavior

The creation of the ApiGatewayV2 route with an AWS StepFunction integration

Current Behavior

Stack deployment failure and rollbacked:

UPDATE_ROLLBACK_COMPLETE: Parameter: stateMachineArn does not fit schema for Operation: StepFunctions-StartSyncExecution. (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException

Reproduction Steps

const demoStateMachine = new StateMachine(scope, 'DemoStateMachine', {
    stateMachineType: StateMachineType.EXPRESS,
    definitionBody: 
        DefinitionBody.fromChainable( 
           new Pass(scope, 'PassState')
        ),
});

const role = new Role(scope, 'DemoStateMachineRole', {
    assumedBy: new ServicePrincipal('apigateway.amazonaws.com'),
});

const integration = new CfnIntegration(
    this.scope,
    "DemoStateMachineIntegration",
    {
        apiId: gateway.httpApiId,
        integrationType: HttpIntegrationType.AWS_PROXY,
        integrationSubtype: 'StepFunctions-StartSyncExecution',
        credentialsArn: role.roleArn,
        payloadFormatVersion: PayloadFormatVersion.VERSION_1_0.version,
        requestParameters: {
            stateMachineArn: demoStateMachine.stateMachineArn
        }
    }
);

new CfnRoute(this.scope, 'CheckoutRoute', {
    apiId: gateway.httpApiId,
    routeKey: `${HttpMethod.POST} demo`,
    authorizationType: 'NONE',
    target: `integrations/${integration.ref}`,
});

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.85.0

Framework Version

2.85.0

Node.js Version

16.18.0

OS

macOS 13.4.1

Language

Typescript

Language Version

4.9.5

Other information

No response

@YishaqG YishaqG added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 11, 2023
@github-actions github-actions bot added the @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 label Jul 11, 2023
@pahud
Copy link
Contributor

pahud commented Jul 12, 2023

Looks like the stateMachineArn is invalid.

requestParameters: {
            stateMachineArn: demoStateMachine.stateMachineArn
        }

Are you able to CfnOutput the value of demoStateMachine.stateMachineArn for troubleshooting?

I guess this might related to #25395 (comment) and a trailing .sync might be required.

@pahud pahud added p2 effort/medium Medium work item – several days of effort response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 12, 2023
@pahud pahud changed the title aws-apigatewayv2: stateMachineArn does not fit schema for Operation: StepFunctions-StartSyncExecution apigatewayv2: stateMachineArn does not fit schema for Operation: StepFunctions-StartSyncExecution Jul 12, 2023
@YishaqG
Copy link
Author

YishaqG commented Jul 13, 2023

What I was trying to do here is not related with #25395 (comment) he is trying to use other services from the StepFunction. What I was trying to do was to invoke a StepFunction from ApiGatewayV2

Done, so it looks like you need to specify it as:

    requestParameters: {
        StateMachineArn: demoStateMachine.stateMachineArn,
        Input: '$request.body.input',
    }

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 13, 2023
@Perminus-Gaita
Copy link

Here is the full code with the imports and all the code that works.

import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { CfnIntegration, CfnRoute, HttpMethod, PayloadFormatVersion } from 'aws-cdk-lib/aws-apigatewayv2'
import { DefinitionBody, StateMachine, StateMachineType, Pass } from 'aws-cdk-lib/aws-stepfunctions';
import { Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import { HttpIntegrationType, HttpApi } from 'aws-cdk-lib/aws-apigatewayv2';


export class MyStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    // ... (your existing code)
    const httpApi = new HttpApi(this, 'MyHttpApi');

    const demoStateMachine = new StateMachine(this, 'DemoStateMachine', {
      stateMachineType: StateMachineType.EXPRESS,
      definitionBody: DefinitionBody.fromChainable(
        new Pass(this, 'PassState')
      ),
    });

    const role = new Role(this, 'DemoStateMachineRole', {
      assumedBy: new ServicePrincipal('apigateway.amazonaws.com'),
    });

    const integration = new CfnIntegration(
      this,
      "DemoStateMachineIntegration",
      {
        apiId: httpApi.httpApiId,
        integrationType: HttpIntegrationType.AWS_PROXY,
        integrationSubtype: 'StepFunctions-StartSyncExecution',
        credentialsArn: role.roleArn,
        payloadFormatVersion: PayloadFormatVersion.VERSION_1_0.version,
        requestParameters: {
            StateMachineArn: demoStateMachine.stateMachineArn,
            Input: '$request.body.input',
        }
      }
    );

    new CfnRoute(this, 'CheckoutRoute', {
      apiId: httpApi.httpApiId,
      routeKey: `${HttpMethod.POST} /demo`,
      authorizationType: 'NONE',
      target: `integrations/${integration.ref}`,
    });
  }
}

@pahud pahud added p3 and removed p2 labels Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 bug This issue is a bug. effort/medium Medium work item – several days of effort p3
Projects
None yet
Development

No branches or pull requests

3 participants