Skip to content

fix(stepfunctions-tasks): Stage field not included in CallApiGatewayHttpApiEndpoint task definition#15755

Merged
mergify[bot] merged 6 commits intoaws:masterfrom
jihndai:issue/14242
Jul 30, 2021
Merged

fix(stepfunctions-tasks): Stage field not included in CallApiGatewayHttpApiEndpoint task definition#15755
mergify[bot] merged 6 commits intoaws:masterfrom
jihndai:issue/14242

Conversation

@jihndai
Copy link
Copy Markdown
Contributor

@jihndai jihndai commented Jul 25, 2021

this.stageName was not initialized by props.stageName when calling CallApiGatewayHttpApiEndpoint's constructor, therefore causing the Stage field to not get rendered even though we specified that property.

fixes #14242


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Jul 25, 2021

@jihndai jihndai changed the title fix(stepfunctions-tasks): "Stage" field not included in task definition when stageName is explicitly defined fix(stepfunctions-tasks): Stage field not included in task definition when stageName is explicitly defined Jul 25, 2021
@jihndai
Copy link
Copy Markdown
Contributor Author

jihndai commented Jul 25, 2021

I'm not sure if the behavior I'll be describing below is intended, but I think it's worth mentioning because it was unexpected.

While playing around with the integration tests in integ.call-http-api.ts, I noticed that although the $default stage will work when calling its base path such as https://{api-id}.execute-api.{region}.amazonaws.com, a non-default stage named test would instead return a 404 Error when called at its base path such as https://{api-id}.execute-api.{aws-region}.amazonaws.com/test. To make the test call work, I needed to add a slash at the end of the url https://{api-id}.execute-api.{aws-region}.amazonaws.com/test/.

So assuming we have setup a stage test and setup an integration in the base path using:

const httpApi = new apigatewayv2.HttpApi(stack, 'MyHttpApi');

httpApi.addStage('Test', {
  stageName: 'test',
  autoDeploy: true,
});

httpApi.addRoutes({
  path: '/',
  integration: new integrations.LambdaProxyIntegration({
    handler: // lambda handler,
  }),
});

This task will run successfully, which uses the default stage:

new CallApiGatewayHttpApiEndpoint(stack, 'Call APIGW', {
  apiId: httpApi.apiId,
  apiStack: cdk.Stack.of(httpApi),
  method: HttpMethod.GET,
});

On the other hand if we specified the stage name test the task would fail:

new CallApiGatewayHttpApiEndpoint(stack, 'Call APIGW Stage', {
  apiId: httpApi.apiId,
  apiStack: cdk.Stack.of(httpApi),
  method: HttpMethod.GET,
  stageName: 'test',
});

To remedy this we would need to assign the apiPath prop with an empty string (which I believe will add the missing / to the api url):

apiPath: '',

Is this intended or should this be considered a bug that requires fixing?

@BenChaimberg BenChaimberg changed the title fix(stepfunctions-tasks): Stage field not included in task definition when stageName is explicitly defined fix(stepfunctions-tasks): Stage field not included in CallApiGatewayHttpApiEndpoint task definition Jul 29, 2021
@BenChaimberg
Copy link
Copy Markdown
Contributor

That is definitely a bug as well, need to add ?? '' in _renderTask (can be fixed in a different PR though)

I took a brief tour through the module and there are a bunch of issues. In fact, I'm not sure how the state machine successfully executes given the very much incorrect ARN that is created when stageName or apiPath are undefined.

resourceName: `${stageName}/${method}${apiPath}`,

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 29, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: dc00fe0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 4f38fe1 into aws:master Jul 30, 2021
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 30, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Aug 3, 2021
…ttpApiEndpoint task definition (aws#15755)

`this.stageName` was not initialized by `props.stageName` when calling `CallApiGatewayHttpApiEndpoint`'s constructor, therefore causing the `Stage` field to not get rendered even though we specified that property.

fixes aws#14242

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
…ttpApiEndpoint task definition (aws#15755)

`this.stageName` was not initialized by `props.stageName` when calling `CallApiGatewayHttpApiEndpoint`'s constructor, therefore causing the `Stage` field to not get rendered even though we specified that property.

fixes aws#14242

----

*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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(@aws-cdk/aws-stepfunction-tasks): CallApiGatewayHttpApiEndpoint didn't include "Stage" during rend the object

4 participants