add_permission
async
¶
add_permission(
function_name: NamespacedFunctionName,
statement_id: StatementId,
action: Action,
principal: Principal,
*,
config_overrides: Optional[AsyncLambdaClientConfig] = 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.
>>> await 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.
>>> await client.add_permission(action='lambda:InvokeFunction', function_name='my-function', principal='223456789012', statement_id='xaccount')
Source code in docs_src/capo_lambda/_services/async__lambda.py
6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 | |