Skip to content

Commit 36a48ad

Browse files
authored
feat(sns): add grantSubscribe method (#30486)
### Issue # (if applicable) Closes #29049. ### Reason for this change Allow the Topic construct to expose a method to grant subscription permissions to a grantable resource. It's useful when you want to allow entities, such as another AWS account or resources created later, to subscribe to the topic at their own pace, separating permission granting from the actual subscription process. ### Description of changes Add grantSubscribe method to ITopic interface and TopicBase class. ### Description of how you validated changes Add unit tests and integ tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 06d0a1b commit 36a48ad

12 files changed

+691
-3
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-topic-grant-subscribe.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-topic-grant-subscribe.js.snapshot/integ.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-topic-grant-subscribe.js.snapshot/manifest.json

+158
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-topic-grant-subscribe.js.snapshot/sns-grant-subscribe-stack.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"Resources": {
3+
"CustomKey1E6D0D07": {
4+
"Type": "AWS::KMS::Key",
5+
"Properties": {
6+
"KeyPolicy": {
7+
"Statement": [
8+
{
9+
"Action": "kms:*",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"AWS": {
13+
"Fn::Join": [
14+
"",
15+
[
16+
"arn:",
17+
{
18+
"Ref": "AWS::Partition"
19+
},
20+
":iam::",
21+
{
22+
"Ref": "AWS::AccountId"
23+
},
24+
":root"
25+
]
26+
]
27+
}
28+
},
29+
"Resource": "*"
30+
}
31+
],
32+
"Version": "2012-10-17"
33+
},
34+
"PendingWindowInDays": 7
35+
},
36+
"UpdateReplacePolicy": "Delete",
37+
"DeletionPolicy": "Delete"
38+
},
39+
"MyTopic86869434": {
40+
"Type": "AWS::SNS::Topic",
41+
"Properties": {
42+
"KmsMasterKeyId": {
43+
"Fn::GetAtt": [
44+
"CustomKey1E6D0D07",
45+
"Arn"
46+
]
47+
}
48+
}
49+
},
50+
"MyUserDC45028B": {
51+
"Type": "AWS::IAM::User"
52+
},
53+
"MyUserDefaultPolicy7B897426": {
54+
"Type": "AWS::IAM::Policy",
55+
"Properties": {
56+
"PolicyDocument": {
57+
"Statement": [
58+
{
59+
"Action": "sns:Subscribe",
60+
"Effect": "Allow",
61+
"Resource": {
62+
"Ref": "MyTopic86869434"
63+
}
64+
}
65+
],
66+
"Version": "2012-10-17"
67+
},
68+
"PolicyName": "MyUserDefaultPolicy7B897426",
69+
"Users": [
70+
{
71+
"Ref": "MyUserDC45028B"
72+
}
73+
]
74+
}
75+
}
76+
},
77+
"Parameters": {
78+
"BootstrapVersion": {
79+
"Type": "AWS::SSM::Parameter::Value<String>",
80+
"Default": "/cdk-bootstrap/hnb659fds/version",
81+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
82+
}
83+
},
84+
"Rules": {
85+
"CheckBootstrapVersion": {
86+
"Assertions": [
87+
{
88+
"Assert": {
89+
"Fn::Not": [
90+
{
91+
"Fn::Contains": [
92+
[
93+
"1",
94+
"2",
95+
"3",
96+
"4",
97+
"5"
98+
],
99+
{
100+
"Ref": "BootstrapVersion"
101+
}
102+
]
103+
}
104+
]
105+
},
106+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
107+
}
108+
]
109+
}
110+
}
111+
}

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-topic-grant-subscribe.js.snapshot/snsgrantsubscribetestDefaultTestDeployAssertE3ABCE3F.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-topic-grant-subscribe.js.snapshot/snsgrantsubscribetestDefaultTestDeployAssertE3ABCE3F.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)