1 | ;
|
2 | var _a;
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.LambdaSubscription = void 0;
|
5 | const jsiiDeprecationWarnings = require("../.warnings.jsii.js");
|
6 | const JSII_RTTI_SYMBOL_1 = Symbol.for("jsii.rtti");
|
7 | const iam = require("@aws-cdk/aws-iam");
|
8 | const sns = require("@aws-cdk/aws-sns");
|
9 | const core_1 = require("@aws-cdk/core");
|
10 | // keep this import separate from other imports to reduce chance for merge conflicts with v2-main
|
11 | // eslint-disable-next-line no-duplicate-imports, import/order
|
12 | const core_2 = require("@aws-cdk/core");
|
13 | /**
|
14 | * Use a Lambda function as a subscription target
|
15 | */
|
16 | class LambdaSubscription {
|
17 | constructor(fn, props = {}) {
|
18 | this.fn = fn;
|
19 | this.props = props;
|
20 | try {
|
21 | jsiiDeprecationWarnings._aws_cdk_aws_sns_subscriptions_LambdaSubscriptionProps(props);
|
22 | }
|
23 | catch (error) {
|
24 | if (process.env.JSII_DEBUG !== "1" && error.name === "DeprecationError") {
|
25 | Error.captureStackTrace(error, LambdaSubscription);
|
26 | }
|
27 | throw error;
|
28 | }
|
29 | }
|
30 | /**
|
31 | * Returns a configuration for a Lambda function to subscribe to an SNS topic
|
32 | */
|
33 | bind(topic) {
|
34 | // Create subscription under *consuming* construct to make sure it ends up
|
35 | // in the correct stack in cases of cross-stack subscriptions.
|
36 | if (!core_2.Construct.isConstruct(this.fn)) {
|
37 | throw new Error('The supplied lambda Function object must be an instance of Construct');
|
38 | }
|
39 | this.fn.addPermission(`AllowInvoke:${core_1.Names.nodeUniqueId(topic.node)}`, {
|
40 | sourceArn: topic.topicArn,
|
41 | principal: new iam.ServicePrincipal('sns.amazonaws.com'),
|
42 | });
|
43 | // if the topic and function are created in different stacks
|
44 | // then we need to make sure the topic is created first
|
45 | if (topic instanceof sns.Topic && topic.stack !== this.fn.stack) {
|
46 | this.fn.stack.addDependency(topic.stack);
|
47 | }
|
48 | return {
|
49 | subscriberScope: this.fn,
|
50 | subscriberId: topic.node.id,
|
51 | endpoint: this.fn.functionArn,
|
52 | protocol: sns.SubscriptionProtocol.LAMBDA,
|
53 | filterPolicy: this.props.filterPolicy,
|
54 | region: this.regionFromArn(topic),
|
55 | deadLetterQueue: this.props.deadLetterQueue,
|
56 | };
|
57 | }
|
58 | regionFromArn(topic) {
|
59 | // no need to specify `region` for topics defined within the same stack.
|
60 | if (topic instanceof sns.Topic) {
|
61 | if (topic.stack !== this.fn.stack) {
|
62 | // only if we know the region, will not work for
|
63 | // env agnostic stacks
|
64 | if (!core_1.Token.isUnresolved(topic.env.region) &&
|
65 | (topic.env.region !== this.fn.env.region)) {
|
66 | return topic.env.region;
|
67 | }
|
68 | }
|
69 | return undefined;
|
70 | }
|
71 | return core_1.Stack.of(topic).splitArn(topic.topicArn, core_1.ArnFormat.SLASH_RESOURCE_NAME).region;
|
72 | }
|
73 | }
|
74 | exports.LambdaSubscription = LambdaSubscription;
|
75 | _a = JSII_RTTI_SYMBOL_1;
|
76 | LambdaSubscription[_a] = { fqn: "@aws-cdk/aws-sns-subscriptions.LambdaSubscription", version: "1.204.0" };
|
77 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGFtYmRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsibGFtYmRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLHdDQUF3QztBQUV4Qyx3Q0FBd0M7QUFDeEMsd0NBQStEO0FBRy9ELGlHQUFpRztBQUNqRyw4REFBOEQ7QUFDOUQsd0NBQTBDO0FBUTFDOztHQUVHO0FBQ0gsTUFBYSxrQkFBa0I7SUFDN0IsWUFBNkIsRUFBb0IsRUFBbUIsUUFBaUMsRUFBRTtRQUExRSxPQUFFLEdBQUYsRUFBRSxDQUFrQjtRQUFtQixVQUFLLEdBQUwsS0FBSyxDQUE4Qjs7Ozs7OytDQUQ1RixrQkFBa0I7Ozs7S0FFNUI7SUF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