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

Change Custom Resource mechanism to make Lambda explicit #35

Merged
merged 3 commits into from
Jun 6, 2018

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Jun 5, 2018

Introducing SingletonLambda which can be instantiated multiple times
but only adds the Lambda to the underlying stack once.

A CustomResource now explicitly takes either a LambdaRef or a TopicRef,
and the Lambda can be a SingletonLambda.

This splitting up makes it possible to establish bidirectional permissions
between the Custom Resource Lambda and other resources, as discussed in #9.

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

Introducing `SingletonLambda` which can be instantiated multiple times
but only adds the Lambda to the underlying stack once.

A CustomResource now explicitly takes either a `LambdaRef` or a `TopicRef`,
and the Lambda can be a SingletonLambda.

This splitting up makes it possible to establish bidirectional permissions
between the Custom Resource Lambda and other resources.
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Jun 5, 2018

The inevitable question here is going to be, "why is SingletonLambda in aws-cdk-custom-resources and not in aws-cdk-lambda?" I considered that, but I think the use case only ever makes sense with Custom Resources, so I kept it there.

constructor(parent: Construct, name: string, props: SingletonLambdaProps) {
super(parent, name);

this.lambdaFunction = this.ensureLambda(slugify(props.uuid), props);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call slugify inside ensureLambda (especially given the name of the param is uuid).
Also, #12

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, yeah, but that's not done yet, so neither is this :)

this.functionName = this.lambdaFunction.functionName;
this.role = this.lambdaFunction.role;

this.canCreatePermissions = true; // Doesn't matter, addPermission is overriden anyway
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why do we need to specify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's abstract in the parent.

@rix0rrr rix0rrr merged commit 6091489 into master Jun 6, 2018
@rix0rrr rix0rrr deleted the huijbers/custom-resource-uses-singleton-lambda branch June 6, 2018 08:15
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants