Lambda / Client / put_resource_policy

put_resource_policy#

Lambda.Client.put_resource_policy(**kwargs)#

Note

The option to create and modify full JSON resource-based policies, and to use the PutResourcePolicy, GetResourcePolicy, and DeleteResourcePolicy APIs, won’t be available in all Amazon Web Services Regions until September 30, 2024.

Adds a resource-based policy to a function. You can use resource-based policies to grant access to other Amazon Web Services accounts, organizations, or services. Resource-based policies apply to a single function, version, or alias.

Warning

Adding a resource-based policy using this API action replaces any existing policy you’ve previously created. This means that if you’ve previously added resource-based permissions to a function using the AddPermission action, those permissions will be overwritten by your new policy.

See also: AWS API Documentation

Request Syntax

response = client.put_resource_policy(
    ResourceArn='string',
    Policy='string',
    RevisionId='string'
)
Parameters:
  • ResourceArn (string) –

    [REQUIRED]

    The Amazon Resource Name (ARN) of the function you want to add the policy to. You can use either a qualified or an unqualified ARN, but the value you specify must be a complete ARN and wildcard characters are not accepted.

  • Policy (string) –

    [REQUIRED]

    The JSON resource-based policy you want to add to your function.

    To learn more about creating resource-based policies for controlling access to Lambda, see Working with resource-based IAM policies in Lambda in the Lambda Developer Guide.

  • RevisionId (string) – Replace the existing policy only if its revision ID matches the string you specify. To find the revision ID of the policy currently attached to your function, use the GetResourcePolicy action.

Return type:

dict

Returns:

Response Syntax

{
    'Policy': 'string',
    'RevisionId': 'string'
}

Response Structure

  • (dict) –

    • Policy (string) –

      The policy Lambda added to your function.

    • RevisionId (string) –

      The revision ID of the policy Lambda added to your function.

Exceptions

  • Lambda.Client.exceptions.ServiceException

  • Lambda.Client.exceptions.ResourceNotFoundException

  • Lambda.Client.exceptions.ResourceConflictException

  • Lambda.Client.exceptions.InvalidParameterValueException

  • Lambda.Client.exceptions.PolicyLengthExceededException

  • Lambda.Client.exceptions.TooManyRequestsException

  • Lambda.Client.exceptions.PreconditionFailedException

  • Lambda.Client.exceptions.PublicPolicyException