You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore: remove references to discouraged grant* methods in examples. (#36784)
In the examples, there are some references to `grant*` methods in L2s, that are now discouraged (though not formally deprecated). Replace these examples with the preferred way, which is using the `grants` attribute of the construct.
Some surrounding text also had to be updated to match the examples.
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy file name to clipboardExpand all lines: packages/aws-cdk-lib/aws-iam/README.md
+14-11Lines changed: 14 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,27 +32,29 @@ Managed policies can be attached using `xxx.addManagedPolicy(ManagedPolicy.fromA
32
32
33
33
## Granting permissions to resources
34
34
35
-
Many of the AWS CDK resources have `grant*` methods that allow you to grant other resources access to that resource. As an example, the following code gives a Lambda function write permissions (Put, Update, Delete) to a DynamoDB table.
35
+
Many of the AWS CDK resources have grant methods (accessible via the `grants` attribute) that allow you to grant other
36
+
resources access to that resource. As an example, the following code gives a Lambda function write permissions
37
+
(Put, Update, Delete) to a DynamoDB table.
36
38
37
39
```ts
38
40
declareconst fn:lambda.Function;
39
41
declareconst table:dynamodb.Table;
40
42
41
-
table.grantWriteData(fn);
43
+
table.grants.writeData(fn);
42
44
```
43
45
44
-
The more generic `grant` method allows you to give specific permissions to a resource:
46
+
The more generic `actions` method allows you to give specific permissions to a resource:
45
47
46
48
```ts
47
49
declareconst fn:lambda.Function;
48
50
declareconst table:dynamodb.Table;
49
51
50
-
table.grant(fn, 'dynamodb:PutItem');
52
+
table.grants.actions(fn, 'dynamodb:PutItem');
51
53
```
52
54
53
-
The `grant*` methods accept an `IGrantable` object. This interface is implemented by IAM principal resources (groups, users and roles), policies, managed policies and resources that assume a role such as a Lambda function, EC2 instance or a Codebuild project.
55
+
The grant methods accept an `IGrantable` object. This interface is implemented by IAM principal resources (groups, users and roles), policies, managed policies and resources that assume a role such as a Lambda function, EC2 instance or a Codebuild project.
54
56
55
-
You can find which `grant*` methods exist for a resource in the [AWS CDK API Reference](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-construct-library.html).
57
+
You can find which grant methods exist for a resource in the [AWS CDK API Reference](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-construct-library.html).
56
58
57
59
## Roles
58
60
@@ -70,8 +72,8 @@ automatically if you associate the construct with other constructs from the
70
72
AWS Construct Library (for example, if you tell an *AWS CodePipeline* to trigger
71
73
an *AWS Lambda Function*, the Pipeline's Role will automatically get
72
74
`lambda:InvokeFunction` permissions on that particular Lambda Function),
73
-
or if you explicitly grant permissions using `grant` functions (see the
74
-
previous section).
75
+
or if you explicitly grant permissions using the public methods in the
76
+
`RoleGrants` class (see the previous section).
75
77
76
78
### Opting out of automatic permissions management
Note that subscriptions of queues in different accounts need to be manually confirmed by
62
62
reading the initial message from the queue and visiting the link found in it.
63
63
64
-
The `grantSubscribe` method adds a policy statement to the topic's resource policy, allowing the specified principal to perform the `sns:Subscribe` action.
64
+
The `topic.grants.subscribe` method adds a policy statement to the topic's resource policy, allowing the specified principal to perform the `sns:Subscribe` action.
65
65
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.
0 commit comments