Class LazyRole
An IAM role that only gets attached to the construct tree once it gets used, not before.
public class LazyRole : Resource, IRole, IIdentity, IPrincipal, IGrantable, IResource, IConstruct, IConstruct, IDependable
- Inheritance
-
LazyRole
- Implements
-
IResourceIConstructIConstructIDependable
Examples
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.IAM;
using Amazon.CDK;
ManagedPolicy managedPolicy;
PolicyDocument policyDocument;
IPrincipal principal;
var lazyRole = new LazyRole(this, "MyLazyRole", new LazyRoleProps {
AssumedBy = principal,
// the properties below are optional
Description = "description",
ExternalId = "externalId",
ExternalIds = new [] { "externalIds" },
InlinePolicies = new Dictionary<string, PolicyDocument> {
{ "inlinePoliciesKey", policyDocument }
},
ManagedPolicies = new [] { managedPolicy },
MaxSessionDuration = Duration.Minutes(30),
Path = "path",
PermissionsBoundary = managedPolicy,
RoleName = "roleName"
});
Remarks
This construct can be used to simplify logic in other constructs which need to create a role but only if certain configurations occur (such as when AutoScaling is configured). The role can be configured in one place, but if it never gets used it doesn't get instantiated and will not be synthesized or deployed.
Resource: AWS::IAM::Role
ExampleMetadata: fixture=_generated
Constructors
LazyRole(Construct, string, ILazyRoleProps)
public LazyRole(Construct scope, string id, ILazyRoleProps props)
Parameters
scope
Constructid
stringprops
ILazyRoleProps
Properties
AssumeRoleAction
When this Principal is used in an AssumeRole policy, the action to use.
public virtual string AssumeRoleAction { get; }
Property Value
GrantPrincipal
The principal to grant permissions to.
public virtual IPrincipal GrantPrincipal { get; }
Property Value
PolicyFragment
Return the policy fragment that identifies this principal in a Policy.
public virtual PrincipalPolicyFragment PolicyFragment { get; }
Property Value
PrincipalAccount
The AWS account ID of this principal.
public virtual string? PrincipalAccount { get; }
Property Value
Remarks
Can be undefined when the account is not known (for example, for service principals). Can be a Token - in that case, it's assumed to be AWS::AccountId.
RoleArn
Returns the ARN of this role.
public virtual string RoleArn { get; }
Property Value
RoleId
Returns the stable and unique string identifying the role (i.e. AIDAJQABLZS4A3QDU576Q).
public virtual string RoleId { get; }
Property Value
Remarks
Attribute: true
RoleName
Returns the name of this role.
public virtual string RoleName { get; }
Property Value
Methods
AddManagedPolicy(IManagedPolicy)
Attaches a managed policy to this role.
public virtual void AddManagedPolicy(IManagedPolicy policy)
Parameters
policy
IManagedPolicyThe managed policy to attach.
AddToPolicy(PolicyStatement)
Add to the policy of this principal.
public virtual bool AddToPolicy(PolicyStatement statement)
Parameters
statement
PolicyStatement
Returns
AddToPrincipalPolicy(PolicyStatement)
Adds a permission to the role's default policy document.
public virtual IAddToPrincipalPolicyResult AddToPrincipalPolicy(PolicyStatement statement)
Parameters
statement
PolicyStatementThe permission statement to add to the policy document.
Returns
Remarks
If there is no default policy attached to this role, it will be created.
AttachInlinePolicy(Policy)
Attaches a policy to this role.
public virtual void AttachInlinePolicy(Policy policy)
Parameters
policy
PolicyThe policy to attach.
Grant(IPrincipal, params string[])
Grant the actions defined in actions to the identity Principal on this resource.
public virtual Grant Grant(IPrincipal identity, params string[] actions)
Parameters
identity
IPrincipalactions
string[]
Returns
GrantAssumeRole(IPrincipal)
Grant permissions to the given principal to assume this role.
public virtual Grant GrantAssumeRole(IPrincipal identity)
Parameters
identity
IPrincipal
Returns
GrantPassRole(IPrincipal)
Grant permissions to the given principal to pass this role.
public virtual Grant GrantPassRole(IPrincipal identity)
Parameters
identity
IPrincipal