Class CfnResourcePolicy
- All Implemented Interfaces:
IInspectable,IEnvironmentAware,IResourcePolicyRef,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct,software.constructs.IDependable
AWS::Lambda::ResourcePolicy resource to attach a resource-based policy to a LAM resource.
A resource-based policy applies to a single LAM resource, for example, a function, function version, or function alias. To learn more about using resource-based policies with LAM, see Working with resource-based policies in in the Developer Guide.
You can use resource-based policies to grant permissions to other AWS services, AWS accounts and organizations, and IAM users and roles to access your LAM resource. You can also deny access to specific entities, and use the full range of IAM global condition keys to further restrict who has access to your LAM resource. For example, you can limit access to calls originating from a specified IP address or VPC.
A resource-based policy is a JSON document containing a number of statements. Each statement defines the entities you want to grant permission to, the API actions you want to allow or deny, and the LAM resource you want the statement to apply to. A statement can also optionally include an array of logical conditions using the IAM global condition keys.
To use the AWS::Lambda::ResourcePolicy resource, make sure that you have the resource-based policy permissions for Lambda.
To learn more about creating resource-based policies, see Policies and permissions in in the User Guide. For more information about example policies for providing permissions to AWS services, other AWS accounts, and IAM users and roles, see Example resource-based policies for functions in the Developer Guide.
Avoid mixing permission resource types
To grant permissions to access your function, we recommend using the AWS::Lambda::ResourcePolicy resource to set access permissions. With this resource, you have more flexibility and fine-grained control than AWS::Lambda::Permission. This resource grants an AWS service or another account permission to call a particular API action on a function.
You can also use the AWS::Lambda::Permission resource, however using both AWS::Lambda::Permission and AWS::Lambda::ResourcePolicy to set permissions on a function can result in errors. Permissions defined in AWS::Lambda::Permission can be unintentionally overwritten, whether in a single CFN stack or across multiple stacks. Don't use both resource types to set permissions on a function.
To migrate existing permissions for a function from AWS::Lambda::Permission to AWS::Lambda::ResourcePolicy, do the following:
- Set a
Retaindeletion policy on theAWS::Lambda::Permissionresources you want to migrate. This is necessary so that Lambda does not delete statements with the same statement ID when you delete these resources. - Use the GetResourcePolicyLAM API to retrieve the resource-based policy currently attached to the function.
- Use this policy to create a new
AWS::Lambda::ResourcePolicyresource. - Delete all the existing
AWS::Lambda::Permissionresources for the function.
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.lambda.*;
Object policyDocument;
CfnResourcePolicy cfnResourcePolicy = CfnResourcePolicy.Builder.create(this, "MyCfnResourcePolicy")
.policyDocument(policyDocument)
.resourceArn("resourceArn")
.build();
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationModeNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.IInspectable
IInspectable.Jsii$Default, IInspectable.Jsii$ProxyNested classes/interfaces inherited from interface software.amazon.awscdk.interfaces.lambda.IResourcePolicyRef
IResourcePolicyRef.Jsii$Default, IResourcePolicyRef.Jsii$Proxy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe CloudFormation resource type name for this resource class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCfnResourcePolicy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedCfnResourcePolicy(software.amazon.jsii.JsiiObjectRef objRef) CfnResourcePolicy(software.constructs.Construct scope, String id, CfnResourcePolicyProps props) Create a newAWS::Lambda::ResourcePolicy. -
Method Summary
Modifier and TypeMethodDescriptionThe policy document you want to add to your LAM resource.The Amazon Resource Name (ARN) of the LAM resource you want to add the policy to.A reference to a ResourcePolicy resource.voidinspect(TreeInspector inspector) Examines the CloudFormation resource and discloses attributes.static BooleanChecks whether the given object is a CfnResourcePolicy.renderProperties(Map<String, Object> props) voidsetPolicyDocument(Object value) The policy document you want to add to your LAM resource.voidsetResourceArn(String value) The Amazon Resource Name (ARN) of the LAM resource you want to add the policy to.Methods inherited from class software.amazon.awscdk.CfnResource
addDeletionOverride, addDependency, addDependsOn, addMetadata, addOverride, addPropertyDeletionOverride, addPropertyOverride, addResourceDependency, addResourceDependency, applyCrossStackReferenceStrength, applyRemovalPolicy, applyRemovalPolicy, applyRemovalPolicy, cfnPropertyName, getAtt, getAtt, getCfnOptions, getCfnResourceType, getEnv, getMetadata, getUpdatedProperites, getUpdatedProperties, isCfnResource, obtainDependencies, removeDependency, removeResourceDependency, replaceDependency, shouldSynthesize, toString, validatePropertiesMethods inherited from class software.amazon.awscdk.CfnRefElement
getRefMethods inherited from class software.amazon.awscdk.CfnElement
getCreationStack, getLogicalId, getStack, isCfnElement, overrideLogicalId, withMethods inherited from class software.constructs.Construct
getNode, isConstructMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.constructs.IConstruct
getNode, withMethods inherited from interface software.amazon.awscdk.interfaces.IEnvironmentAware
getEnvMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Field Details
-
CFN_RESOURCE_TYPE_NAME
The CloudFormation resource type name for this resource class.
-
-
Constructor Details
-
CfnResourcePolicy
protected CfnResourcePolicy(software.amazon.jsii.JsiiObjectRef objRef) -
CfnResourcePolicy
protected CfnResourcePolicy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
CfnResourcePolicy
@Stability(Stable) public CfnResourcePolicy(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull CfnResourcePolicyProps props) Create a newAWS::Lambda::ResourcePolicy.- Parameters:
scope- Scope in which this resource is defined. This parameter is required.id- Construct identifier for this resource (unique in its scope). This parameter is required.props- Resource properties. This parameter is required.
-
-
Method Details
-
isCfnResourcePolicy
Checks whether the given object is a CfnResourcePolicy.- Parameters:
x- This parameter is required.
-
inspect
Examines the CloudFormation resource and discloses attributes.- Specified by:
inspectin interfaceIInspectable- 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:
renderPropertiesin classCfnResource- Parameters:
props- This parameter is required.
-
getCfnProperties
- Overrides:
getCfnPropertiesin classCfnResource
-
getCfnPropertyNames
- Overrides:
getCfnPropertyNamesin classCfnResource
-
getResourcePolicyRef
A reference to a ResourcePolicy resource.- Specified by:
getResourcePolicyRefin interfaceIResourcePolicyRef
-
getPolicyDocument
The policy document you want to add to your LAM resource. -
setPolicyDocument
The policy document you want to add to your LAM resource. -
getResourceArn
The Amazon Resource Name (ARN) of the LAM resource you want to add the policy to. -
setResourceArn
The Amazon Resource Name (ARN) of the LAM resource you want to add the policy to.
-