class Grant
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.IAM.Grant |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsiam#Grant |
Java | software.amazon.awscdk.services.iam.Grant |
Python | aws_cdk.aws_iam.Grant |
TypeScript (source) | aws-cdk-lib » aws_iam » Grant |
Implements
IDependable
Result of a grant() operation.
This class is not instantiable by consumers on purpose, so that they will be required to call the Grant factory functions.
Example
declare const instance: ec2.Instance;
declare const volume: ec2.Volume;
const attachGrant = volume.grantAttachVolumeByResourceTag(instance.grantPrincipal, [instance]);
const detachGrant = volume.grantDetachVolumeByResourceTag(instance.grantPrincipal, [instance]);
Properties
Name | Type | Description |
---|---|---|
principal | Policy [] | The statements that were added to the principal's policy. |
resource | Policy [] | The statements that were added to the principal's policy. |
success | boolean | Whether the grant operation was successful. |
principal | Policy | The statement that was added to the principal's policy. |
resource | Policy | The statement that was added to the resource policy. |
principalStatements
Type:
Policy
[]
The statements that were added to the principal's policy.
resourceStatements
Type:
Policy
[]
The statements that were added to the principal's policy.
success
Type:
boolean
Whether the grant operation was successful.
principalStatement?
⚠️ Deprecated: Use principalStatements
instead
Type:
Policy
(optional)
The statement that was added to the principal's policy.
resourceStatement?
⚠️ Deprecated: Use resourceStatements
instead
Type:
Policy
(optional)
The statement that was added to the resource policy.
Methods
Name | Description |
---|---|
apply | Make sure this grant is applied before the given constructs are deployed. |
assert | Throw an error if this grant wasn't successful. |
combine(rhs) | Combine two grants into a new one. |
static add | Try to grant the given permissions to the given principal. |
static add | Add a grant both on the principal and on the resource. |
static add | Grant the given permissions to the principal. |
static drop(grantee, _intent) | Returns a "no-op" Grant object which represents a "dropped grant". |
Before(...constructs)
applypublic applyBefore(...constructs: IConstruct[]): void
Parameters
- constructs
IConstruct
Make sure this grant is applied before the given constructs are deployed.
The same as construct.node.addDependency(grant), but slightly nicer to read.
Success()
assertpublic assertSuccess(): void
Throw an error if this grant wasn't successful.
combine(rhs)
public combine(rhs: Grant): Grant
Parameters
- rhs
Grant
Returns
Combine two grants into a new one.
ToPrincipal(options)
static addpublic static addToPrincipal(options: GrantOnPrincipalOptions): Grant
Parameters
- options
Grant
On Principal Options
Returns
Try to grant the given permissions to the given principal.
Absence of a principal leads to a warning, but failing to add the permissions to a present principal is not an error.
ToPrincipalAndResource(options)
static addpublic static addToPrincipalAndResource(options: GrantOnPrincipalAndResourceOptions): Grant
Parameters
Returns
Add a grant both on the principal and on the resource.
As long as any principal is given, granting on the principal may fail (in case of a non-identity principal), but granting on the resource will never fail.
Statement will be the resource statement.
ToPrincipalOrResource(options)
static addpublic static addToPrincipalOrResource(options: GrantWithResourceOptions): Grant
Parameters
- options
Grant
With Resource Options
Returns
Grant the given permissions to the principal.
The permissions will be added to the principal policy primarily, falling back to the resource policy if necessary. The permissions must be granted somewhere.
- Trying to grant permissions to a principal that does not admit adding to the principal policy while not providing a resource with a resource policy is an error.
- Trying to grant permissions to an absent principal (possible in the case of imported resources) leads to a warning being added to the resource construct.
static drop(grantee, _intent)
public static drop(grantee: IGrantable, _intent: string): Grant
Parameters
- grantee
IGrantable
— The intended grantee. - _intent
string
— The user's intent (will be ignored at the moment).
Returns
Returns a "no-op" Grant
object which represents a "dropped grant".
This can be used for e.g. imported resources where you may not be able to modify the resource's policy or some underlying policy which you don't know about.