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(sns): create subscriptions in consumer scope #3065

Merged
merged 13 commits into from
Jun 27, 2019
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-sns-subscriptions/lib/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ export class LambdaSubscription implements sns.ITopicSubscription {
throw new Error(`The supplied lambda Function object must be an instance of Construct`);
}

this.fn.addPermission(topic.node.id, {
this.fn.addPermission(`AllowInvoke:${topic.node.uniqueId}`, {
sourceArn: topic.topicArn,
principal: new iam.ServicePrincipal('sns.amazonaws.com'),
});

return {
subscriberId: this.fn.node.id,
scope: this.fn,
subscriberId: topic.node.id,
endpoint: this.fn.functionArn,
protocol: sns.SubscriptionProtocol.LAMBDA,
filterPolicy: this.props.filterPolicy,
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-sns-subscriptions/lib/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export class SqsSubscription implements sns.ITopicSubscription {
}));

return {
subscriberId: this.queue.node.id,
scope: this.queue,
subscriberId: topic.node.uniqueId,
endpoint: this.queue.queueArn,
protocol: sns.SubscriptionProtocol.SQS,
rawMessageDelivery: this.props.rawMessageDelivery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,6 @@
"MyTopic86869434": {
"Type": "AWS::SNS::Topic"
},
"MyTopicEchoD1E0EE5C": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Protocol": "lambda",
"TopicArn": {
"Ref": "MyTopic86869434"
},
"Endpoint": {
"Fn::GetAtt": [
"Echo11F3FB29",
"Arn"
]
}
}
},
"MyTopicFiltered55457D11": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Protocol": "lambda",
"TopicArn": {
"Ref": "MyTopic86869434"
},
"Endpoint": {
"Fn::GetAtt": [
"Filtered186C0D0A",
"Arn"
]
},
"FilterPolicy": {
"color": [
"red",
{
"prefix": "bl"
},
{
"prefix": "ye"
}
],
"size": [
{
"anything-but": [
"small",
"medium"
]
}
],
"price": [
{
"numeric": [
">=",
100,
"<=",
200
]
}
]
}
}
},
"EchoServiceRoleBE28060B": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -122,7 +63,7 @@
"EchoServiceRoleBE28060B"
]
},
"EchoMyTopicF6EBB45F": {
"EchoAllowInvokeawscdksnslambdaMyTopic6C62AB907F727CDA": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
Expand All @@ -138,6 +79,21 @@
}
}
},
"EchoMyTopic4CB8819E": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Protocol": "lambda",
"TopicArn": {
"Ref": "MyTopic86869434"
},
"Endpoint": {
"Fn::GetAtt": [
"Echo11F3FB29",
"Arn"
]
}
}
},
"FilteredServiceRole16D9DDC1": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -198,7 +154,7 @@
"FilteredServiceRole16D9DDC1"
]
},
"FilteredMyTopic804BCBC3": {
"FilteredAllowInvokeawscdksnslambdaMyTopic6C62AB90A2EA1666": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
Expand All @@ -213,6 +169,50 @@
"Ref": "MyTopic86869434"
}
}
},
"FilteredMyTopicC8395C27": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Protocol": "lambda",
"TopicArn": {
"Ref": "MyTopic86869434"
},
"Endpoint": {
"Fn::GetAtt": [
"Filtered186C0D0A",
"Arn"
]
},
"FilterPolicy": {
"color": [
"red",
{
"prefix": "bl"
},
{
"prefix": "ye"
}
],
"size": [
{
"anything-but": [
"small",
"medium"
]
}
],
"price": [
{
"numeric": [
">=",
100,
"<=",
200
]
}
]
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@
"MyTopic86869434": {
"Type": "AWS::SNS::Topic"
},
"MyTopicMyQueueFA241964": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Protocol": "sqs",
"TopicArn": {
"Ref": "MyTopic86869434"
},
"Endpoint": {
"Fn::GetAtt": [
"MyQueueE6CA6235",
"Arn"
]
}
}
},
"MyQueueE6CA6235": {
"Type": "AWS::SQS::Queue"
},
Expand Down Expand Up @@ -55,6 +40,21 @@
}
]
}
},
"MyQueueawscdksnssqsMyTopic9361DEA223429051": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Protocol": "sqs",
"TopicArn": {
"Ref": "MyTopic86869434"
},
"Endpoint": {
"Fn::GetAtt": [
"MyQueueE6CA6235",
"Arn"
]
}
}
}
}
}
Loading