Skip to content

add_layer_version_permission

add_layer_version_permission(
    layer_name: LayerName,
    version_number: LayerVersionNumber,
    statement_id: StatementId,
    action: LayerPermissionAllowedAction,
    principal: LayerPermissionAllowedPrincipal,
    *,
    config_overrides: Optional[LambdaClientConfig] = None,
    organization_id: Optional[OrganizationId] = None,
    revision_id: Optional[String] = None,
) -> AddLayerVersionPermissionResponse

Adds permissions to the resource-based policy of a version of an Lambda layer. Use this action to grant layer usage permission to other accounts. You can grant permission to a single account, all accounts in an organization, or all Amazon Web Services accounts.

To revoke permission, call RemoveLayerVersionPermission with the statement ID that you specified when you added it.

Parameters:

  • layer_name (LayerName) –

    The name or Amazon Resource Name (ARN) of the layer.

  • version_number (LayerVersionNumber) –

    The version number.

  • statement_id (StatementId) –

    An identifier that distinguishes the policy from others on the same layer version.

  • action (LayerPermissionAllowedAction) –

    The API action that grants access to the layer. For example, lambda:GetLayerVersion.

  • principal (LayerPermissionAllowedPrincipal) –

    An account ID, or * to grant layer usage permission to all accounts in an organization, or all Amazon Web Services accounts (if organizationId is not specified). For the last case, make sure that you really do want all Amazon Web Services accounts to have usage permission to this layer.

  • organization_id (Optional[OrganizationId], default: None ) –

    With the principal set to *, grant permission to all accounts in the specified organization.

  • revision_id (Optional[String], default: None ) –

    Only update the policy if the revision ID matches the ID specified. Use this option to avoid modifying a policy that has changed since you last read it.

Raises:

Examples:

To add permissions to a layer version The following example grants permission for the account 223456789012 to use version 1 of a layer named my-layer.

>>> client.add_layer_version_permission(action='lambda:GetLayerVersion', layer_name='my-layer', principal='223456789012', statement_id='xaccount', version_number=1)
Source code in docs_src/capo_lambda/_services/_lambda.py
def add_layer_version_permission(
    self,
    layer_name: "capo_lambda.types.layer_name.LayerName",
    version_number: "capo_lambda.types.layer_version_number.LayerVersionNumber",
    statement_id: "capo_lambda.types.statement_id.StatementId",
    action: "capo_lambda.types.layer_permission_allowed_action.LayerPermissionAllowedAction",
    principal: "capo_lambda.types.layer_permission_allowed_principal.LayerPermissionAllowedPrincipal",
    *,
    config_overrides: Optional[LambdaClientConfig] = None,
    organization_id: Optional[
        "capo_lambda.types.organization_id.OrganizationId"
    ] = None,
    revision_id: Optional["capo_lambda.types.string.String"] = None,
) -> "capo_lambda.types.add_layer_version_permission_response.AddLayerVersionPermissionResponse":
    """<p>Adds permissions to the resource-based policy of a version of an <a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html">Lambda layer</a>. Use this action to grant layer usage permission to other accounts. You can grant permission to a single account, all accounts in an organization, or all Amazon Web Services accounts. </p> <p>To revoke permission, call <a>RemoveLayerVersionPermission</a> with the statement ID that you specified when you added it.</p>

    Args:
        layer_name: <p>The name or Amazon Resource Name (ARN) of the layer.</p>
        version_number: <p>The version number.</p>
        statement_id: <p>An identifier that distinguishes the policy from others on the same layer version.</p>
        action: <p>The API action that grants access to the layer. For example, <code>lambda:GetLayerVersion</code>.</p>
        principal: <p>An account ID, or <code>*</code> to grant layer usage permission to all accounts in an organization, or all Amazon Web Services accounts (if <code>organizationId</code> is not specified). For the last case, make sure that you really do want all Amazon Web Services accounts to have usage permission to this layer. </p>
        organization_id: <p>With the principal set to <code>*</code>, grant permission to all accounts in the specified organization.</p>
        revision_id: <p>Only update the policy if the revision ID matches the ID specified. Use this option to avoid modifying a policy that has changed since you last read it.</p>

    Raises:
        capo_lambda.errors.invalid_parameter_value_exception.InvalidParameterValueException: <p>One of the parameters in the request is not valid.</p>
        capo_lambda.errors.policy_length_exceeded_exception.PolicyLengthExceededException: <p>The permissions policy for the resource is too large. For more information, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html">Lambda quotas</a>.</p>
        capo_lambda.errors.precondition_failed_exception.PreconditionFailedException: <p>The RevisionId provided does not match the latest RevisionId for the Lambda function or alias.</p> <ul> <li> <p> <b>For AddPermission and RemovePermission API operations:</b> Call <code>GetPolicy</code> to retrieve the latest RevisionId for your resource.</p> </li> <li> <p> <b>For all other API operations:</b> Call <code>GetFunction</code> or <code>GetAlias</code> to retrieve the latest RevisionId for your resource.</p> </li> </ul>
        capo_lambda.errors.resource_conflict_exception.ResourceConflictException: <p>The resource already exists, or another operation is in progress.</p>
        capo_lambda.errors.resource_not_found_exception.ResourceNotFoundException: <p>The resource specified in the request does not exist.</p>
        capo_lambda.errors.service_exception.ServiceException: <p>The Lambda service encountered an internal error.</p>
        capo_lambda.errors.too_many_requests_exception.TooManyRequestsException: <p>The request throughput limit was exceeded. For more information, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html#api-requests">Lambda quotas</a>.</p>
        capo_lambda.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To add permissions to a layer version
        The following example grants permission for the account 223456789012 to use version 1 of a layer named my-layer.

        >>> client.add_layer_version_permission(action='lambda:GetLayerVersion', layer_name='my-layer', principal='223456789012', statement_id='xaccount', version_number=1)
    """

    def _handler(
        req: "OperationRequest[capo_lambda.types.add_layer_version_permission_request.AddLayerVersionPermissionRequest]",
    ) -> OperationResponse[
        "capo_lambda.types.add_layer_version_permission_response.AddLayerVersionPermissionResponse"
    ]:
        import capo_lambda._operations.aws_gir_api_service.add_layer_version_permission

        output, http_response = (
            capo_lambda._operations.aws_gir_api_service.add_layer_version_permission.add_layer_version_permission(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AddLayerVersionPermission")
    )
    input_: capo_lambda.types.add_layer_version_permission_request.AddLayerVersionPermissionRequest = {
        "layer_name": layer_name,
        "version_number": version_number,
        "statement_id": statement_id,
        "action": action,
        "principal": principal,
    }
    if organization_id is not None:
        input_["organization_id"] = organization_id
    if revision_id is not None:
        input_["revision_id"] = revision_id

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output