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:
.
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.
Topics
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:Layer |
CreateAlias DeleteAlias DeleteFunction DeleteFunctionConcurrency GetAlias GetFunction GetFunctionConfiguration GetPolicy ListAliases ListVersionsByFunction PublishVersion PutFunctionConcurrency UpdateAlias UpdateFunctionCode | Function | None |
GetAccountSettings ListFunctions ListTags TagResource UntagResource | * |
None |
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 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.
Layers
Action | Resource | Condition |
---|---|---|
AddLayerVersionPermission RemoveLayerVersionPermission GetLayerVersion GetLayerVersionPolicy DeleteLayerVersion | Layer version | None |
PublishLayerVersion | Layer | None |
ListLayers ListLayerVersions | * |
None |