add_permission
¶
add_permission(
function_name: NamespacedFunctionName,
statement_id: StatementId,
action: Action,
principal: Principal,
*,
config_overrides: Optional[LambdaClientConfig] = None,
source_arn: Optional[Arn] = None,
function_url_auth_type: Optional[FunctionUrlAuthType] = None,
invoked_via_function_url: Optional[InvokedViaFunctionUrl] = None,
source_account: Optional[SourceOwner] = None,
event_source_token: Optional[EventSourceToken] = None,
qualifier: Optional[NumericLatestPublishedOrAliasQualifier] = None,
revision_id: Optional[String] = None,
principal_org_id: Optional[PrincipalOrgID] = None,
) -> AddPermissionResponse
Grants a principal permission to use a function. You can apply the policy at the function level, or specify a qualifier to restrict access to a single version or alias. If you use a qualifier, the invoker must use the full Amazon Resource Name (ARN) of that version or alias to invoke the function. Note: Lambda does not support adding policies to version $LATEST.
To grant permission to another account, specify the account ID as the Principal. To grant permission to an organization defined in Organizations, specify the organization ID as the PrincipalOrgID. For Amazon Web Services services, the principal is a domain-style identifier that the service defines, such as s3.amazonaws.com or sns.amazonaws.com. For Amazon Web Services services, you can also specify the ARN of the associated resource as the SourceArn. If you grant permission to a service principal without specifying the source, other accounts could potentially configure resources in their account to invoke your Lambda function.
This operation adds a statement to a resource-based permissions policy for the function. For more information about function policies, see Using resource-based policies for Lambda.
Parameters:
-
function_name(NamespacedFunctionName) –The name or ARN of the Lambda function, version, or alias.
Name formats
-
Function name –
my-function(name-only),my-function:v1(with alias). -
Function ARN –
arn:aws:lambda:us-west-2:123456789012:function:my-function. -
Partial ARN –
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.
-
-
statement_id(StatementId) –A statement identifier that differentiates the statement from others in the same policy.
-
action(Action) –The action that the principal can use on the function. For example,
lambda:InvokeFunctionorlambda:GetFunction. -
principal(Principal) –The Amazon Web Services service, Amazon Web Services account, IAM user, or IAM role that invokes the function. If you specify a service, use
SourceArnorSourceAccountto limit who can invoke the function through that service. -
source_arn(Optional[Arn], default:None) –For Amazon Web Services services, the ARN of the Amazon Web Services resource that invokes the function. For example, an Amazon S3 bucket or Amazon SNS topic.
Note that Lambda configures the comparison using the
StringLikeoperator. -
function_url_auth_type(Optional[FunctionUrlAuthType], default:None) –The type of authentication that your function URL uses. Set to
AWS_IAMif you want to restrict access to authenticated users only. Set toNONEif you want to bypass IAM authentication to create a public endpoint. For more information, see Control access to Lambda function URLs. -
invoked_via_function_url(Optional[InvokedViaFunctionUrl], default:None) –Indicates whether the permission applies when the function is invoked through a function URL.
-
source_account(Optional[SourceOwner], default:None) –For Amazon Web Services service, the ID of the Amazon Web Services account that owns the resource. Use this together with
SourceArnto ensure that the specified account owns the resource. It is possible for an Amazon S3 bucket to be deleted by its owner and recreated by another account. -
event_source_token(Optional[EventSourceToken], default:None) –For Alexa Smart Home functions, a token that the invoker must supply.
-
qualifier(Optional[NumericLatestPublishedOrAliasQualifier], default:None) –Specify a version or alias to add permissions to a published version of the function.
-
revision_id(Optional[String], default:None) –Update the policy only if the revision ID matches the ID that's specified. Use this option to avoid modifying a policy that has changed since you last read it.
-
principal_org_id(Optional[PrincipalOrgID], default:None) –The identifier for your organization in Organizations. Use this to grant permissions to all the Amazon Web Services accounts under this organization.
Raises:
-
InvalidParameterValueException–One of the parameters in the request is not valid.
-
PolicyLengthExceededException–The permissions policy for the resource is too large. For more information, see Lambda quotas.
-
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.
-
-
PublicPolicyException–The resource-based policy you tried to add to the Lambda resource would grant public access to it, which isn't allowed.
-
ResourceConflictException–The resource already exists, or another operation is in progress.
-
ResourceNotFoundException–The resource specified in the request does not exist.
-
ServiceException–The Lambda service encountered an internal error.
-
TooManyRequestsException–The request throughput limit was exceeded. For more information, see Lambda quotas.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To grant Amazon S3 permission to invoke a function The following example adds permission for Amazon S3 to invoke a Lambda function named my-function for notifications from a bucket named my-bucket-1xpuxmplzrlbh in account 123456789012.
>>> client.add_permission(action='lambda:InvokeFunction', function_name='my-function', principal='s3.amazonaws.com', source_account='123456789012', source_arn='arn:aws:s3:::my-bucket-1xpuxmplzrlbh/*', statement_id='s3')
To grant another account permission to invoke a function
The following example adds permission for account 223456789012 invoke a Lambda function named my-function.
>>> client.add_permission(action='lambda:InvokeFunction', function_name='my-function', principal='223456789012', statement_id='xaccount')
Source code in docs_src/capo_lambda/_services/_lambda.py
6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 | |