class CfnResourcePolicyPropsMixin (mixin)
| Language | Type name |
|---|---|
.NET | Amazon.CDK.CfnPropertyMixins.AWS.Lambda.CfnResourcePolicyPropsMixin |
Go | github.com/aws/aws-cdk-go/awscdkcfnpropertymixins/v2/awslambda#CfnResourcePolicyPropsMixin |
Java | software.amazon.awscdk.cfnpropertymixins.services.lambda.CfnResourcePolicyPropsMixin |
Python | aws_cdk.cfn_property_mixins.aws_lambda.CfnResourcePolicyPropsMixin |
TypeScript | @aws-cdk/cfn-property-mixins » aws_lambda » CfnResourcePolicyPropsMixin |
Implements
IMixin
Extends
Mixin
Use the 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 { aws_lambda as lambda } from '@aws-cdk/cfn-property-mixins';
import * as cdk from 'aws-cdk-lib';
declare const mergeStrategy: cdk.IMergeStrategy;
declare const policyDocument: any;
const cfnResourcePolicyPropsMixin = new lambda.CfnResourcePolicyPropsMixin({
policyDocument: policyDocument,
resourceArn: 'resourceArn',
}, /* all optional props */ {
strategy: mergeStrategy,
});
Initializer
new CfnResourcePolicyPropsMixin(props: CfnResourcePolicyMixinProps, options?: CfnPropertyMixinOptions)
Parameters
- props
Cfn— L1 properties to apply.Resource Policy Mixin Props - options
Cfn— Mixin options.Property Mixin Options
Create a mixin to apply properties to AWS::Lambda::ResourcePolicy.
Properties
| Name | Type | Description |
|---|---|---|
| props | Cfn | |
| strategy | IMerge | |
| static CFN_PROPERTY_KEYS | string[] |
props
Type:
Cfn
strategy
Type:
IMerge
static CFN_PROPERTY_KEYS
Type:
string[]
Methods
| Name | Description |
|---|---|
| apply | Apply the mixin properties to the construct. |
| supports(construct) | Check if this mixin supports the given construct. |
applyTo(construct)
public applyTo(construct: IConstruct): void
Parameters
- construct
IConstruct
Apply the mixin properties to the construct.
supports(construct)
public supports(construct: IConstruct): boolean
Parameters
- construct
IConstruct
Returns
boolean
Check if this mixin supports the given construct.

.NET
Go
Java
Python
TypeScript