Class CfnPolicy

All Implemented Interfaces:
IConstruct, IDependable, IInspectable, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:29:57.258Z") @Stability(Stable) public class CfnPolicy extends CfnResource implements IInspectable
A CloudFormation AWS::IAM::Policy.

Adds or updates an inline policy document that is embedded in the specified IAM user, group, or role.

An IAM user can also have a managed policy attached to it. For information about policies, see Managed Policies and Inline Policies in the IAM User Guide .

The Groups, Roles, and Users properties are optional. However, you must specify at least one of these properties.

For information about policy documents see Creating IAM policies in the IAM User Guide .

For information about limits on the number of inline policies that you can embed in an identity, see Limitations on IAM Entities in the IAM User Guide .

Example:

 // The code below shows an example of how to instantiate this type.
 // The values are placeholders you should change.
 import software.amazon.awscdk.services.iam.*;
 Object policyDocument;
 CfnPolicy cfnPolicy = CfnPolicy.Builder.create(this, "MyCfnPolicy")
         .policyDocument(policyDocument)
         .policyName("policyName")
         // the properties below are optional
         .groups(List.of("groups"))
         .roles(List.of("roles"))
         .users(List.of("users"))
         .build();
 
  • Field Details

    • CFN_RESOURCE_TYPE_NAME

      @Stability(Stable) public static final String CFN_RESOURCE_TYPE_NAME
      The CloudFormation resource type name for this resource class.
  • Constructor Details

    • CfnPolicy

      protected CfnPolicy(software.amazon.jsii.JsiiObjectRef objRef)
    • CfnPolicy

      protected CfnPolicy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • CfnPolicy

      @Stability(Stable) public CfnPolicy(@NotNull Construct scope, @NotNull String id, @NotNull CfnPolicyProps props)
      Create a new AWS::IAM::Policy.

      Parameters:
      scope -
      • scope in which this resource is defined.
      This parameter is required.
      id -
      • scoped id of the resource.
      This parameter is required.
      props -
      • resource properties.
      This parameter is required.
  • Method Details

    • inspect

      @Stability(Stable) public void inspect(@NotNull TreeInspector inspector)
      Examines the CloudFormation resource and discloses attributes.

      Specified by:
      inspect in interface IInspectable
      Parameters:
      inspector -
      • tree inspector to collect and process attributes.
      This parameter is required.
    • renderProperties

      @Stability(Stable) @NotNull protected Map<String,Object> renderProperties(@NotNull Map<String,Object> props)
      Overrides:
      renderProperties in class CfnResource
      Parameters:
      props - This parameter is required.
    • getCfnProperties

      @Stability(Stable) @NotNull protected Map<String,Object> getCfnProperties()
      Overrides:
      getCfnProperties in class CfnResource
    • getPolicyDocument

      @Stability(Stable) @NotNull public Object getPolicyDocument()
      The policy document.

      You must provide policies in JSON format in IAM. However, for AWS CloudFormation templates formatted in YAML, you can provide the policy in JSON or YAML format. AWS CloudFormation always converts a YAML policy to JSON format before submitting it to IAM.

      The regex pattern used to validate this parameter is a string of characters consisting of the following:

      • Any printable ASCII character ranging from the space character ( \ u0020 ) through the end of the ASCII character range
      • The printable characters in the Basic Latin and Latin-1 Supplement character set (through \ u00FF )
      • The special characters tab ( \ u0009 ), line feed ( \ u000A ), and carriage return ( \ u000D )
    • setPolicyDocument

      @Stability(Stable) public void setPolicyDocument(@NotNull Object value)
      The policy document.

      You must provide policies in JSON format in IAM. However, for AWS CloudFormation templates formatted in YAML, you can provide the policy in JSON or YAML format. AWS CloudFormation always converts a YAML policy to JSON format before submitting it to IAM.

      The regex pattern used to validate this parameter is a string of characters consisting of the following:

      • Any printable ASCII character ranging from the space character ( \ u0020 ) through the end of the ASCII character range
      • The printable characters in the Basic Latin and Latin-1 Supplement character set (through \ u00FF )
      • The special characters tab ( \ u0009 ), line feed ( \ u000A ), and carriage return ( \ u000D )
    • getPolicyName

      @Stability(Stable) @NotNull public String getPolicyName()
      The name of the policy document.

      This parameter allows (through its regex pattern ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-

    • setPolicyName

      @Stability(Stable) public void setPolicyName(@NotNull String value)
      The name of the policy document.

      This parameter allows (through its regex pattern ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-

    • getGroups

      @Stability(Stable) @Nullable public List<String> getGroups()
      The name of the group to associate the policy with.

      This parameter allows (through its regex pattern ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-.

    • setGroups

      @Stability(Stable) public void setGroups(@Nullable List<String> value)
      The name of the group to associate the policy with.

      This parameter allows (through its regex pattern ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-.

    • getRoles

      @Stability(Stable) @Nullable public List<String> getRoles()
      The name of the role to associate the policy with.

      This parameter allows (per its regex pattern ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-

      If an external policy (such as AWS::IAM::Policy or AWS::IAM::ManagedPolicy ) has a Ref to a role and if a resource (such as AWS::ECS::Service ) also has a Ref to the same role, add a DependsOn attribute to the resource to make the resource depend on the external policy. This dependency ensures that the role's policy is available throughout the resource's lifecycle. For example, when you delete a stack with an AWS::ECS::Service resource, the DependsOn attribute ensures that AWS CloudFormation deletes the AWS::ECS::Service resource before deleting its role's policy.

    • setRoles

      @Stability(Stable) public void setRoles(@Nullable List<String> value)
      The name of the role to associate the policy with.

      This parameter allows (per its regex pattern ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-

      If an external policy (such as AWS::IAM::Policy or AWS::IAM::ManagedPolicy ) has a Ref to a role and if a resource (such as AWS::ECS::Service ) also has a Ref to the same role, add a DependsOn attribute to the resource to make the resource depend on the external policy. This dependency ensures that the role's policy is available throughout the resource's lifecycle. For example, when you delete a stack with an AWS::ECS::Service resource, the DependsOn attribute ensures that AWS CloudFormation deletes the AWS::ECS::Service resource before deleting its role's policy.

    • getUsers

      @Stability(Stable) @Nullable public List<String> getUsers()
      The name of the user to associate the policy with.

      This parameter allows (through its regex pattern ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-

    • setUsers

      @Stability(Stable) public void setUsers(@Nullable List<String> value)
      The name of the user to associate the policy with.

      This parameter allows (through its regex pattern ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-