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

fix(triggers): store provider as class property #29669

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/aws-cdk-lib/triggers/lib/trigger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Construct, IConstruct, Node } from 'constructs';
import * as lambda from '../../aws-lambda';
import { CustomResource, Duration } from '../../core';
import { CustomResource, Duration, CustomResourceProvider } from '../../core';
import { TriggerProvider } from '../../custom-resource-handlers/dist/triggers/trigger-provider.generated';

/**
Expand Down Expand Up @@ -111,20 +111,21 @@ export interface TriggerProps extends TriggerOptions {
* Triggers an AWS Lambda function during deployment.
*/
export class Trigger extends Construct implements ITrigger {
crProvider: CustomResourceProvider;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we either call this provider or use the whole customResourceProvider?

constructor(scope: Construct, id: string, props: TriggerProps) {
super(scope, id);

const provider = TriggerProvider.getOrCreateProvider(this, 'AWSCDK.TriggerCustomResourceProvider');
this.crProvider = TriggerProvider.getOrCreateProvider(this, 'AWSCDK.TriggerCustomResourceProvider');

provider.addToRolePolicy({
this.crProvider.addToRolePolicy({
Effect: 'Allow',
Action: ['lambda:InvokeFunction'],
Resource: [`${props.handler.functionArn}:*`],
});

new CustomResource(this, 'Default', {
resourceType: 'Custom::Trigger',
serviceToken: provider.serviceToken,
serviceToken: this.crProvider.serviceToken,
properties: {
HandlerArn: props.handler.currentVersion.functionArn,
InvocationType: props.invocationType ?? 'RequestResponse',
Expand Down
Loading