Select your cookie preferences

We use cookies and similar tools to enhance your experience, provide our services, deliver relevant advertising, and make improvements. Approved third parties also use these tools to help us deliver advertising and provide certain site features.

aws-cdk-lib

Version 2 of the AWS Cloud Development Kit library


AWS icon

AWS

1,867,929 Weekly downloads

Author Amazon Web Services

Published

Repository github.com

License Apache-2.0

Registry www.npmjs.com


CfnUserPolicy

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

An IAM user can also have a managed policy attached to it. To attach a managed policy to a user, use AWS::IAM::User . To create a new managed policy, use AWS::IAM::ManagedPolicy . For information about policies, see Managed policies and inline policies in the IAM User Guide .

For information about the maximum number of inline policies that you can embed in a user, see IAM and AWS STS quotas in the IAM User Guide .

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-userpolicy.html

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;
CfnUserPolicy cfnUserPolicy = CfnUserPolicy.Builder.create(this, "MyCfnUserPolicy")
.policyName("policyName")
.userName("userName")
// the properties below are optional
.policyDocument(policyDocument)
.build();

Initializers

import software.amazon.awscdk.services.iam.CfnUserPolicy;
CfnUserPolicy.Builder.create(Construct scope, java.lang.String id)
.policyName(java.lang.String)
.userName(java.lang.String)
// .policyDocument(java.lang.Object)
.build();
NameTypeDescription
scopeConstructScope in which this resource is defined.
idjava.lang.StringConstruct identifier for this resource (unique in its scope).
policyNamejava.lang.StringThe name of the policy document.
userNamejava.lang.StringThe name of the user to associate the policy with.
policyDocumentjava.lang.ObjectThe policy document.
scopeRequired

Scope in which this resource is defined.

idRequired
  • Type: java.lang.String

Construct identifier for this resource (unique in its scope).

policyNameRequired
  • Type: java.lang.String

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: _+=,.@-

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-userpolicy.html#cfn-iam-userpolicy-policyname

userNameRequired
  • Type: java.lang.String

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: _+=,.@-

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-userpolicy.html#cfn-iam-userpolicy-username

policyDocumentOptional
  • Type: java.lang.Object

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 )

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-userpolicy.html#cfn-iam-userpolicy-policydocument

Methods

NameDescription
toStringReturns a string representation of this construct.
overrideLogicalIdOverrides the auto-generated logical ID with a specific ID.
addDeletionOverrideSyntactic sugar for addOverride(path, undefined).
addDependencyIndicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.
addDependsOnIndicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.
addMetadataAdd a value to the CloudFormation Resource Metadata.
addOverrideAdds an override to the synthesized CloudFormation resource.
addPropertyDeletionOverrideAdds an override that deletes the value of a property from the resource definition.
addPropertyOverrideAdds an override to a resource property.
applyRemovalPolicySets the deletion policy of the resource based on the removal policy specified.
getAttReturns a token for an runtime attribute of this resource.
getMetadataRetrieve a value value from the CloudFormation Resource Metadata.
obtainDependenciesRetrieves an array of resources this resource depends on.
obtainResourceDependenciesGet a shallow copy of dependencies between this resource and other resources in the same stack.
removeDependencyIndicates that this resource no longer depends on another resource.
replaceDependencyReplaces one dependency with another.
inspectExamines the CloudFormation resource and discloses attributes.
toString
public java.lang.String toString()

Returns a string representation of this construct.

overrideLogicalId
public void overrideLogicalId(java.lang.String newLogicalId)

Overrides the auto-generated logical ID with a specific ID.

newLogicalIdRequired
  • Type: java.lang.String

The new logical ID to use for this stack element.

addDeletionOverride
public void addDeletionOverride(java.lang.String path)

Syntactic sugar for addOverride(path, undefined).

pathRequired
  • Type: java.lang.String

The path of the value to delete.

addDependency
public void addDependency(CfnResource target)

Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.

This can be used for resources across stacks (or nested stack) boundaries and the dependency will automatically be transferred to the relevant scope.

targetRequired
addDependsOn
public void addDependsOn(CfnResource target)

Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.

targetRequired
addMetadata
public void addMetadata(java.lang.String key, java.lang.Object value)

Add a value to the CloudFormation Resource Metadata.

[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.)

keyRequired
  • Type: java.lang.String
valueRequired
  • Type: java.lang.Object
addOverride
public void addOverride(java.lang.String path, java.lang.Object value)

Adds an override to the synthesized CloudFormation resource.

To add a property override, either use addPropertyOverride or prefix path with "Properties." (i.e. Properties.TopicName).

If the override is nested, separate each nested level using a dot (.) in the path parameter. If there is an array as part of the nesting, specify the index in the path.

To include a literal . in the property name, prefix with a \. In most programming languages you will need to write this as "\\." because the \ itself will need to be escaped.

For example,

cfnResource.addOverride("Properties.GlobalSecondaryIndexes.0.Projection.NonKeyAttributes", List.of("myattribute"));
cfnResource.addOverride("Properties.GlobalSecondaryIndexes.1.ProjectionType", "INCLUDE");

would add the overrides

"Properties": {
"GlobalSecondaryIndexes": [
{
"Projection": {
"NonKeyAttributes": [ "myattribute" ]
...
}
...
},
{
"ProjectionType": "INCLUDE"
...
},
]
...
}

The value argument to addOverride will not be processed or translated in any way. Pass raw JSON values in here with the correct capitalization for CloudFormation. If you pass CDK classes or structs, they will be rendered with lowercased key names, and CloudFormation will reject the template.

pathRequired
  • Type: java.lang.String

The path of the property, you can use dot notation to override values in complex types.

Any intermediate keys will be created as needed.

valueRequired
  • Type: java.lang.Object

The value.

Could be primitive or complex.

addPropertyDeletionOverride
public void addPropertyDeletionOverride(java.lang.String propertyPath)

Adds an override that deletes the value of a property from the resource definition.

propertyPathRequired
  • Type: java.lang.String

The path to the property.

addPropertyOverride
public void addPropertyOverride(java.lang.String propertyPath, java.lang.Object value)

Adds an override to a resource property.

Syntactic sugar for addOverride("Properties.<...>", value).

propertyPathRequired
  • Type: java.lang.String

The path of the property.

valueRequired
  • Type: java.lang.Object

The value.

applyRemovalPolicy
public void applyRemovalPolicy()
public void applyRemovalPolicy(RemovalPolicy policy)
public void applyRemovalPolicy(RemovalPolicy policy, RemovalPolicyOptions options)

Sets the deletion policy of the resource based on the removal policy specified.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN). In some cases, a snapshot can be taken of the resource prior to deletion (RemovalPolicy.SNAPSHOT). A list of resources that support this policy can be found in the following link:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html#aws-attribute-deletionpolicy-options

policyOptional
optionsOptional
getAtt
public Reference getAtt(java.lang.String attributeName)
public Reference getAtt(java.lang.String attributeName, ResolutionTypeHint typeHint)

Returns a token for an runtime attribute of this resource.

Ideally, use generated attribute accessors (e.g. resource.arn), but this can be used for future compatibility in case there is no generated attribute.

attributeNameRequired
  • Type: java.lang.String

The name of the attribute.

typeHintOptional
getMetadata
public java.lang.Object getMetadata(java.lang.String key)

Retrieve a value value from the CloudFormation Resource Metadata.

[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.)

keyRequired
  • Type: java.lang.String
obtainDependencies
public java.util.List<Stack OR CfnResource> obtainDependencies()

Retrieves an array of resources this resource depends on.

This assembles dependencies on resources across stacks (including nested stacks) automatically.

obtainResourceDependencies
public java.util.List<CfnResource> obtainResourceDependencies()

Get a shallow copy of dependencies between this resource and other resources in the same stack.

removeDependency
public void removeDependency(CfnResource target)

Indicates that this resource no longer depends on another resource.

This can be used for resources across stacks (including nested stacks) and the dependency will automatically be removed from the relevant scope.

targetRequired
replaceDependency
public void replaceDependency(CfnResource target, CfnResource newTarget)

Replaces one dependency with another.

targetRequired

The dependency to replace.

newTargetRequired

The new dependency to add.

inspect
public void inspect(TreeInspector inspector)

Examines the CloudFormation resource and discloses attributes.

inspectorRequired

tree inspector to collect and process attributes.

Static Functions

NameDescription
isConstructChecks if x is a construct.
isCfnElementReturns true if a construct is a stack element (i.e. part of the synthesized cloudformation template).
isCfnResourceCheck whether the given object is a CfnResource.
isConstruct
import software.amazon.awscdk.services.iam.CfnUserPolicy;
CfnUserPolicy.isConstruct(java.lang.Object x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired
  • Type: java.lang.Object

Any object.

isCfnElement
import software.amazon.awscdk.services.iam.CfnUserPolicy;
CfnUserPolicy.isCfnElement(java.lang.Object x)

Returns true if a construct is a stack element (i.e. part of the synthesized cloudformation template).

Uses duck-typing instead of instanceof to allow stack elements from different versions of this library to be included in the same stack.

xRequired
  • Type: java.lang.Object
isCfnResource
import software.amazon.awscdk.services.iam.CfnUserPolicy;
CfnUserPolicy.isCfnResource(java.lang.Object x)

Check whether the given object is a CfnResource.

xRequired
  • Type: java.lang.Object

Properties

NameTypeDescription
nodeNodeThe tree node.
creationStackjava.util.List<java.lang.String>No description.
logicalIdjava.lang.StringThe logical ID for this CloudFormation stack element.
stackStackThe stack in which this element is defined.
refjava.lang.StringReturn a string that will be resolved to a CloudFormation { Ref } for this element.
cfnOptionsICfnResourceOptionsOptions for this resource, such as condition, update policy etc.
cfnResourceTypejava.lang.StringAWS resource type.
policyNamejava.lang.StringThe name of the policy document.
userNamejava.lang.StringThe name of the user to associate the policy with.
policyDocumentjava.lang.ObjectThe policy document.
nodeRequired
public Node getNode();

The tree node.

creationStackRequired
public java.util.List<java.lang.String> getCreationStack();
  • Type: java.util.List<java.lang.String>
logicalIdRequired
public java.lang.String getLogicalId();
  • Type: java.lang.String

The logical ID for this CloudFormation stack element.

The logical ID of the element is calculated from the path of the resource node in the construct tree.

To override this value, use overrideLogicalId(newLogicalId).

stackRequired
public Stack getStack();

The stack in which this element is defined.

CfnElements must be defined within a stack scope (directly or indirectly).

refRequired
public java.lang.String getRef();
  • Type: java.lang.String

Return a string that will be resolved to a CloudFormation { Ref } for this element.

If, by any chance, the intrinsic reference of a resource is not a string, you could coerce it to an IResolvable through Lazy.any({ produce: resource.ref }).

cfnOptionsRequired
public ICfnResourceOptions getCfnOptions();

Options for this resource, such as condition, update policy etc.

cfnResourceTypeRequired
public java.lang.String getCfnResourceType();
  • Type: java.lang.String

AWS resource type.

policyNameRequired
public java.lang.String getPolicyName();
  • Type: java.lang.String

The name of the policy document.

userNameRequired
public java.lang.String getUserName();
  • Type: java.lang.String

The name of the user to associate the policy with.

policyDocumentOptional
public java.lang.Object getPolicyDocument();
  • Type: java.lang.Object

The policy document.

Constants

NameTypeDescription
CFN_RESOURCE_TYPE_NAMEjava.lang.StringThe CloudFormation resource type name for this resource class.
CFN_RESOURCE_TYPE_NAMERequired
public java.lang.String getCfnResourceTypeName();
  • Type: java.lang.String

The CloudFormation resource type name for this resource class.