Permission

class aws_cdk.aws_lambda.Permission(*, principal, action=None, event_source_token=None, function_url_auth_type=None, scope=None, source_account=None, source_arn=None)

Bases: object

Represents a permission statement that can be added to a Lambda function’s resource policy via the addPermission() method.

Parameters:
  • principal (IPrincipal) – The entity for which you are granting permission to invoke the Lambda function. This entity can be any valid AWS service principal, such as s3.amazonaws.com or sns.amazonaws.com, or, if you are granting cross-account permission, an AWS account ID. For example, you might want to allow a custom application in another AWS account to push events to Lambda by invoking your function. The principal can be either an AccountPrincipal or a ServicePrincipal.

  • action (Optional[str]) – The Lambda actions that you want to allow in this statement. For example, you can specify lambda:CreateFunction to specify a certain action, or use a wildcard (lambda:*) to grant permission to all Lambda actions. For a list of actions, see Actions and Condition Context Keys for AWS Lambda in the IAM User Guide. Default: ‘lambda:InvokeFunction’

  • event_source_token (Optional[str]) – A unique token that must be supplied by the principal invoking the function. Default: The caller would not need to present a token.

  • function_url_auth_type (Optional[FunctionUrlAuthType]) – The authType for the function URL that you are granting permissions for. Default: - No functionUrlAuthType

  • scope (Optional[Construct]) – The scope to which the permission constructs be attached. The default is the Lambda function construct itself, but this would need to be different in cases such as cross-stack references where the Permissions would need to sit closer to the consumer of this permission (i.e., the caller). Default: - The instance of lambda.IFunction

  • source_account (Optional[str]) – The AWS account ID (without hyphens) of the source owner. For example, if you specify an S3 bucket in the SourceArn property, this value is the bucket owner’s account ID. You can use this property to ensure that all source principals are owned by a specific account.

  • source_arn (Optional[str]) – The ARN of a resource that is invoking your function. When granting Amazon Simple Storage Service (Amazon S3) permission to invoke your function, specify this property with the bucket ARN as its value. This ensures that events generated only from the specified bucket, not just any bucket from any AWS account that creates a mapping to your function, can invoke the function.

ExampleMetadata:

infused

Example:

# fn: lambda.Function

principal = iam.ServicePrincipal("my-service")

fn.grant_invoke(principal)

# Equivalent to:
fn.add_permission("my-service Invocation",
    principal=principal
)

Attributes

action

The Lambda actions that you want to allow in this statement.

For example, you can specify lambda:CreateFunction to specify a certain action, or use a wildcard (lambda:*) to grant permission to all Lambda actions. For a list of actions, see Actions and Condition Context Keys for AWS Lambda in the IAM User Guide.

Default:

‘lambda:InvokeFunction’

event_source_token

A unique token that must be supplied by the principal invoking the function.

Default:

The caller would not need to present a token.

function_url_auth_type

The authType for the function URL that you are granting permissions for.

Default:
  • No functionUrlAuthType

principal

The entity for which you are granting permission to invoke the Lambda function.

This entity can be any valid AWS service principal, such as s3.amazonaws.com or sns.amazonaws.com, or, if you are granting cross-account permission, an AWS account ID. For example, you might want to allow a custom application in another AWS account to push events to Lambda by invoking your function.

The principal can be either an AccountPrincipal or a ServicePrincipal.

scope

The scope to which the permission constructs be attached.

The default is the Lambda function construct itself, but this would need to be different in cases such as cross-stack references where the Permissions would need to sit closer to the consumer of this permission (i.e., the caller).

Default:
  • The instance of lambda.IFunction

source_account

The AWS account ID (without hyphens) of the source owner.

For example, if you specify an S3 bucket in the SourceArn property, this value is the bucket owner’s account ID. You can use this property to ensure that all source principals are owned by a specific account.

source_arn

The ARN of a resource that is invoking your function.

When granting Amazon Simple Storage Service (Amazon S3) permission to invoke your function, specify this property with the bucket ARN as its value. This ensures that events generated only from the specified bucket, not just any bucket from any AWS account that creates a mapping to your function, can invoke the function.