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

[apigateway] Allow import of API Gateway Resource #4432

Closed
1 of 2 tasks
dehli opened this issue Oct 9, 2019 · 4 comments · Fixed by #12785
Closed
1 of 2 tasks

[apigateway] Allow import of API Gateway Resource #4432

dehli opened this issue Oct 9, 2019 · 4 comments · Fixed by #12785
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@dehli
Copy link
Contributor

dehli commented Oct 9, 2019

It would be great if we could add a Resource.fromResourceId for API Gateway resources. I could imagine it looking something like this:

Resource.fromResourceId(scope, "Id", {
  restApi,
  resourceId: "abcdef"
});

Use Case

We have existing CloudFormation infrastructure that we're integrating with CDK and it would be great to utilize Resource without having to always use CfnResource.

Proposed Solution

I'd imagine it would behave similarly to Role.fromRoleArn() or RestApi.fromRestApiId(). Will try to get a PR created but wanted to open this issue in case there was a reason it doesn't exist yet.

My initial solution creates a class like below:

const fromResourceId = (scope: Construct, id: string, props: {
  path?: string;
  resourceId: string;
  restApi: IRestApi;
}): ResourceBase => {
  class Import extends ResourceBase {
    public readonly defaultIntegration: Integration;
    public readonly defaultMethodOptions: MethodOptions;
    public readonly parentResource: IResource;
    public readonly path: string = props.path || '/';
    public readonly restApi = props.restApi as RestApi;
    public readonly resourceId: string = props.resourceId;
  }
  return new Import(scope, id);
}

Currently I have restApi as an IRestApi instead of a regular RestApi because that's the return value of RestApi.fromRestApiId(). I'll need to do some work to figure out the proper typing.

Edit: Looks like calling addMethod when using IRestApi doesn't work because there's no stage associated with the API.

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

This is a 🚀 Feature Request

@dehli dehli added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 9, 2019
@SomayaB SomayaB added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Oct 9, 2019
@NGL321 NGL321 removed the needs-triage This issue or PR still needs to be triaged. label Oct 10, 2019
@NGL321
Copy link
Contributor

NGL321 commented Oct 10, 2019

Hey @dehli,

This seems like a reasonable feature request! It would be wonderful if you wanted to put in a PR for it, and I will make sure it is reviewed.

That aside, someone should update this issue when there is progress.

😸

@nija-at nija-at changed the title Allow importing/exporting API Gateway Resources [apigateway] Allow import and export of API Gateway Resources Oct 18, 2019
@Marty-Me
Copy link

Hi CDK team and @dehli,

Has there been any progress on this issue, as we are currently facing the same problems.
I've tried looking at the problem myself, but the issue didn't seem to easy to solve.

@nija-at nija-at changed the title [apigateway] Allow import and export of API Gateway Resources [apigateway] Allow import of API Gateway Resource Feb 5, 2020
@nija-at nija-at added the effort/medium Medium work item – several days of effort label Feb 5, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 6, 2020

See also #1477 which has more discussion and workaround code.

@nija-at nija-at added effort/small Small work item – less than a day of effort p1 and removed effort/medium Medium work item – several days of effort labels Aug 25, 2020
@mergify mergify bot closed this as completed in #12785 Feb 3, 2021
mergify bot pushed a commit that referenced this issue Feb 3, 2021
feat(apigateway): add fromResourceAttribute helper for importing Resource

closes #4432

NOTE: No change in Readme is done since I was not able to find a good place for it in the Readme.


----

*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

github-actions bot commented Feb 3, 2021

⚠️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.

NovakGu pushed a commit to NovakGu/aws-cdk that referenced this issue Feb 18, 2021
feat(apigateway): add fromResourceAttribute helper for importing Resource

closes aws#4432

NOTE: No change in Readme is done since I was not able to find a good place for it in the Readme.


----

*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-apigateway Related to Amazon API Gateway effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants