Resources and conditions for Lambda actions - AWS Lambda

Resources and conditions for Lambda actions

You can restrict the scope of a user's permissions by specifying resources and conditions in an IAM policy. Each API action supports a combination of resource and condition types that varies depending on the behavior of the action.

Every IAM policy statement grants permission to an action that's performed on a resource. When the action doesn't act on a named resource, or when you grant permission to perform the action on all resources, the value of the resource in the policy is a wildcard (*). For many API actions, you can restrict the resources that a user can modify by specifying the Amazon Resource Name (ARN) of a resource, or an ARN pattern that matches multiple resources.

To restrict permissions by resource, specify the resource by ARN.

Lambda resource ARN format

  • Function – arn:aws:lambda:us-west-2:123456789012:function:my-function

  • Function version – arn:aws:lambda:us-west-2:123456789012:function:my-function:1

  • Function alias – arn:aws:lambda:us-west-2:123456789012:function:my-function:TEST

  • Event source mapping – arn:aws:lambda:us-west-2:123456789012:event-source-mapping:fa123456-14a1-4fd2-9fec-83de64ad683de6d47

  • Layer – arn:aws:lambda:us-west-2:123456789012:layer:my-layer

  • Layer version – arn:aws:lambda:us-west-2:123456789012:layer:my-layer:1

For example, the following policy allows a user in account 123456789012 to invoke a function named my-function in the US West (Oregon) Region.

Example invoke function policy

{ "Version": "2012-10-17", "Statement": [ { "Sid": "Invoke", "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], "Resource": "arn:aws:lambda:us-west-2:123456789012:function:my-function" } ] }

This is a special case where the action identifier (lambda:InvokeFunction) differs from the API operation (Invoke). For other actions, the action identifier is the operation name prefixed by lambda:.

Policy conditions

Conditions are an optional policy element that applies additional logic to determine if an action is allowed. In addition to common conditions supported by all actions, Lambda defines condition types that you can use to restrict the values of additional parameters on some actions.

For example, the lambda:Principal condition lets you restrict the service or account that a user can grant invocation access to on a function's resource-based policy. The following policy lets a user grant permission to SNS topics to invoke a function named test.

Example manage function policy permissions

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ManageFunctionPolicy", "Effect": "Allow", "Action": [ "lambda:AddPermission", "lambda:RemovePermission" ], "Resource": "arn:aws:lambda:us-west-2:123456789012:function:test:*", "Condition": { "StringEquals": { "lambda:Principal": "sns.amazonaws.com" } } } ] }

The condition requires that the principal is Amazon SNS and not another service or account. The resource pattern requires that the function name is test and includes a version number or alias. For example, test:v1.

For more information on resources and conditions for Lambda and other AWS services, see Actions, resources, and condition keys in the IAM User Guide.

Function resource names

You reference a Lambda function in a policy statement using an Amazon Resource Name (ARN). The format of a function ARN depends on whether you are referencing the whole function (unqualified) or a function version or alias (qualified).

When making Lambda API calls, users can specify a version or alias by passing a version ARN or alias ARN in the GetFunction FunctionName parameter, or by setting a value in the GetFunction Qualifier parameter. Lambda makes authorization decisions by comparing the resource element in the IAM policy with both the FunctionName and Qualifier passed in API calls. If there is a misamtch, Lambda denies the request.

Whether you are allowing or denying an action on your function, you must use the correct function ARN types in your policy statement to achieve the results that you expect. For example, if your policy references the unqualified ARN, Lambda accepts requests that reference the unqualified ARN but denies requests that reference a qualified ARN.

Note

You can't use a wildcard character to match the Account ID. For more information on accepted syntax, see IAM JSON policy reference.

Example allowing invocation of an unqualified arn

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "lambda:InvokeFunction", "Resource": "arn:aws:lambda:us-west-2:123456789012:function:myFunction" } ] }

If your policy references a specific qualified ARN, Lambda accepts requests that reference that ARN but denies requests that reference the unqualified ARN or a different qualified ARN, for example, myFunction:2.

Example allowing invocation of a specific qualified arn

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "lambda:InvokeFunction", "Resource": "arn:aws:lambda:us-west-2:123456789012:function:myFunction:1" } ] }

If your policy references any qualified ARN using :*, Lambda accepts any qualified ARN but denies requests that reference the unqualified ARN.

Example allowing invocation of any qualified arn

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "lambda:InvokeFunction", "Resource": "arn:aws:lambda:us-west-2:123456789012:function:myFunction:*" } ] }

If your policy references any ARN using *, Lambda accepts any qualified or unqualified ARN.

Example allowing invocation of any qualified or unqualified arn

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "lambda:InvokeFunction", "Resource": "arn:aws:lambda:us-west-2:123456789012:function:myFunction*" } ] }

Function actions

Actions that operate on a function can be restricted to a specific function by function, version, or alias ARN, as described in the following table. Actions that don't support resource restrictions can only be granted for all resources (*).

Functions
Action Resource Condition

AddPermission

RemovePermission

Function

Function version

Function alias

lambda:Principal

Invoke

Permission: lambda:InvokeFunction

Function

Function version

Function alias

None

CreateFunction

UpdateFunctionConfiguration

Function

lambda:CodeSigningConfigArn

lambda:Layer

lambda:VpcIds

lambda:SubnetIds

lambda:SecurityGroupIds

CreateAlias

DeleteAlias

DeleteFunction

DeleteFunctionConcurrency

GetAlias

GetFunction

GetFunctionConfiguration

GetPolicy

ListAliases

ListVersionsByFunction

PublishVersion

PutFunctionConcurrency

UpdateAlias

UpdateFunctionCode

Function

None

GetAccountSettings

ListFunctions

ListTags

TagResource

UntagResource

*

None

Event source mapping actions

For event source mappings, delete and update permissions can be restricted to a specific event source. The lambda:FunctionArn condition lets you restrict which functions a user can configure an event source to invoke.

For these actions, the resource is the event source mapping, so Lambda provides a condition that lets you restrict permission based on the function that the event source mapping invokes.

Event source mappings
Action Resource Condition

DeleteEventSourceMapping

UpdateEventSourceMapping

Event source mapping

lambda:FunctionArn

CreateEventSourceMapping

*

lambda:FunctionArn

GetEventSourceMapping

ListEventSourceMappings

*

None

Layer actions

Layer actions let you restrict the layers that a user can manage or use with a function. Actions related to layer use and permissions act on a version of a layer, while PublishLayerVersion acts on a layer name. You can use either with wildcards to restrict the layers that a user can work with by name.

Note

Note: the GetLayerVersion action also covers GetLayerVersionByArn. Lambda does not support GetLayerVersionByArn as an IAM action.