PutResourcePolicy
Adds a resource-based policy to a Lambda resource. Resource-based policies grant access to other AWS accounts, organizations, or services. Resource-based policies apply to a single Lambda resource (for example, a function, function version, or function alias).
Important
This operation replaces any existing policy on the Lambda resource. If you previously added permissions using the AddPermission operation, the new policy overwrites those permissions.
Request Syntax
PUT /2026-07-09/resource-policy/ResourceArn HTTP/1.1
Content-type: application/json
{
"Policy": "string",
"RevisionId": "string"
}
URI Request Parameters
The request uses the following URI parameters.
- ResourceArn
-
The Amazon Resource Name (ARN) of the Lambda resource you want to add the policy to. You can use a qualified or an unqualified ARN. The value must be a complete ARN, and the operation does not accept wildcard characters.
Length Constraints: Minimum length of 0. Maximum length of 256.
Pattern:
arn:(aws[a-zA-Z-]*)?:lambda:(eusc-)?[a-z]{2}((-gov)|(-iso([a-z]?)))?-[a-z]+-\d{1}:\d{12}:function:[a-zA-Z0-9-_]+(:(\$LATEST(\.PUBLISHED)?|[a-zA-Z0-9-_])+)?Required: Yes
Request Body
The request accepts the following data in JSON format.
- Policy
-
The policy document you want to add to your Lambda resource. This is formatted as a JSON string.
For more information, see Working with resource-based policies in Lambda in the AWS Lambda Developer Guide.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 20480.
Pattern:
[\s\S]+Required: Yes
- RevisionId
-
The revision ID that the existing policy must match for the replacement to proceed. If the revision ID doesn't match, the operation fails with a
PreconditionFailedExceptionerror. To retrieve the current revision ID, use the GetResourcePolicy operation.Type: String
Length Constraints: Fixed length of 36.
Pattern:
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}Required: No
Response Syntax
HTTP/1.1 200
Content-type: application/json
{
"Policy": "string",
"RevisionId": "string"
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- Policy
-
The resource-based policy that Lambda adds to the resource.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 20480.
Pattern:
[\s\S]+ - RevisionId
-
The revision ID of the policy that Lambda adds to your Lambda resource.
Type: String
Length Constraints: Fixed length of 36.
Pattern:
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
Errors
For information about the errors that are common to all actions, see Common Error Types.
- InvalidParameterValueException
-
One of the parameters in the request is not valid.
- message
-
The exception message.
- Type
-
The exception type.
HTTP Status Code: 400
- PolicyLengthExceededException
-
The permissions policy for the resource is too large. For more information, see Lambda quotas.
HTTP Status Code: 400
- PreconditionFailedException
-
The RevisionId provided does not match the latest RevisionId for the Lambda function or alias.
-
For AddPermission and RemovePermission API operations: Call
GetPolicyto retrieve the latest RevisionId for your resource. -
For all other API operations: Call
GetFunctionorGetAliasto retrieve the latest RevisionId for your resource.
- message
-
The exception message.
- Type
-
The exception type.
HTTP Status Code: 412
-
- PublicPolicyException
-
The resource-based policy you tried to add to the Lambda resource would grant public access to it, which isn't allowed.
- Message
-
The exception message.
- Type
-
The exception type.
HTTP Status Code: 400
- ResourceConflictException
-
The resource already exists, or another operation is in progress.
- message
-
The exception message.
- Type
-
The exception type.
HTTP Status Code: 409
- ResourceNotFoundException
-
The resource specified in the request does not exist.
HTTP Status Code: 404
- ServiceException
-
The AWS Lambda service encountered an internal error.
HTTP Status Code: 500
- TooManyRequestsException
-
The request throughput limit was exceeded. For more information, see Lambda quotas.
- retryAfterSeconds
-
The number of seconds the caller should wait before retrying.
HTTP Status Code: 429
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: