Lambda.Client.
get_policy
(**kwargs)¶Returns the resource-based IAM policy for a function, version, or alias.
See also: AWS API Documentation
Request Syntax
response = client.get_policy(
FunctionName='string',
Qualifier='string'
)
[REQUIRED]
The name of the Lambda function, version, or alias.
Name formats
my-function
(name-only), my-function:v1
(with alias).arn:aws:lambda:us-west-2:123456789012:function:my-function
.123456789012:function:my-function
.You can append a version number or alias to any of the formats. The length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.
dict
Response Syntax
{
'Policy': 'string',
'RevisionId': 'string'
}
Response Structure
(dict) --
Policy (string) --
The resource-based policy.
RevisionId (string) --
A unique identifier for the current revision of the policy.
Exceptions
Lambda.Client.exceptions.ServiceException
Lambda.Client.exceptions.ResourceNotFoundException
Lambda.Client.exceptions.TooManyRequestsException
Lambda.Client.exceptions.InvalidParameterValueException
Examples
The following example returns the resource-based policy for version 1 of a Lambda function named my-function.
response = client.get_policy(
FunctionName='my-function',
Qualifier='1',
)
print(response)
Expected Output:
{
'Policy': '{"Version":"2012-10-17","Id":"default","Statement":[{"Sid":"xaccount","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::123456789012:root"},"Action":"lambda:InvokeFunction","Resource":"arn:aws:lambda:us-east-2:123456789012:function:my-function:1"}]}',
'RevisionId': '4843f2f6-7c59-4fda-b484-afd0bc0e22b8',
'ResponseMetadata': {
'...': '...',
},
}