How to use the aws-cdk.ServicePrincipal function in aws-cdk

To help you get started, we’ve selected a few aws-cdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cdk / packages / aws-cdk-sns / lib / topic-ref.ts View on Github external
public get eventRuleTarget(): EventRuleTarget {
        if (!this.eventRuleTargetPolicyAdded) {
            this.addToResourcePolicy(new PolicyStatement()
                .addAction('sns:Publish')
                .addPrincipal(new ServicePrincipal('events.amazonaws.com'))
                .addResource(this.topicArn));

            this.eventRuleTargetPolicyAdded = true;
        }

        return {
            id: this.name,
            arn: this.topicArn,
        };
    }
}
github aws / aws-cdk / packages / aws-cdk-sns / lib / topic-ref.ts View on Github external
public subscribeLambda(lambdaFunction: LambdaRef) {
        const subscriptionName = lambdaFunction.name + 'Subscription';

        if (this.tryFindChild(subscriptionName)) {
            throw new Error(`A subscription between the topic ${this.name} and the lambda ${lambdaFunction.name} already exists`);
        }

        const sub = new Subscription(this, subscriptionName, {
            topic: this,
            endpoint: lambdaFunction.functionArn,
            protocol: SubscriptionProtocol.Lambda
        });

        lambdaFunction.addPermission(this.name, {
            sourceArn: this.topicArn,
            principal: new ServicePrincipal('sns.amazonaws.com'),
        });

        return sub;
    }

aws-cdk

CDK Toolkit, the command line tool for CDK apps

Apache-2.0
Latest version published 4 days ago

Package Health Score

95 / 100
Full package analysis