id
stringlengths
14
16
text
stringlengths
1
2.43k
source
stringlengths
99
229
fa0c36dea1de-2
![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/xray-servicemap-function.png) You can instrument your handler code to record metadata and trace downstream calls\. To record detail about calls that your handler makes to other resources and services, use the X\-Ray SDK for Python\. To get the SDK, add the `aws-xray-sdk` package to your application's dependencies\. **Example [blank\-python/function/requirements\.txt](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/blank-python/function/requirements.txt)** ``` jsonpickle==1.3 aws-xray-sdk==2.4.3 ``` To instrument AWS SDK clients, patch the `boto3` library with the `aws_xray_sdk.core` module\. **Example [blank\-python/function/lambda\_function\.py](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/blank-python/function/lambda_function.py) – Tracing an AWS SDK client** ``` import boto3 from aws_xray_sdk.core import xray_recorder
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/python-tracing.md
fa0c36dea1de-3
``` import boto3 from aws_xray_sdk.core import xray_recorder from aws_xray_sdk.core import patch_all logger = logging.getLogger() logger.setLevel(logging.INFO) patch_all() client = boto3.client('lambda') client.get_account_settings() def lambda_handler(event, context): logger.info('## ENVIRONMENT VARIABLES\r' + jsonpickle.encode(dict(**os.environ))) ... ``` The following example shows a trace with 2 segments\. Both are named **my\-function**, but one is type `AWS::Lambda` and the other is `AWS::Lambda::Function`\. The function segment is expanded to show its subsegments\. ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/nodejs-xray-timeline.png) The first segment represents the invocation request processed by the Lambda service\. The second segment records the work done by your function\. The function segment has 3 subsegments\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/python-tracing.md
fa0c36dea1de-4
The first segment represents the invocation request processed by the Lambda service\. The second segment records the work done by your function\. The function segment has 3 subsegments\. + **Initialization** – Represents time spent loading your function and running [initialization code](gettingstarted-features.md#gettingstarted-features-programmingmodel)\. This subsegment only appears for the first event processed by each instance of your function\. + **Invocation** – Represents the work done by your handler code\. By instrumenting your code, you can extend this subsegment with additional subsegments\. + **Overhead** – Represents the work done by the Lambda runtime to prepare to handle the next event\. You can also instrument HTTP clients, record SQL queries, and create custom subsegments with annotations and metadata\. For more information, see [The X\-Ray SDK for Python](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-python.html) in the AWS X\-Ray Developer Guide\. **Topics** + [Enabling active tracing with the Lambda API](#python-tracing-api) + [Enabling active tracing with AWS CloudFormation](#python-tracing-cloudformation) + [Storing runtime dependencies in a layer](#python-tracing-layers)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/python-tracing.md
24879b0aa716-0
To manage tracing configuration with the AWS CLI or AWS SDK, use the following API operations: + [UpdateFunctionConfiguration](API_UpdateFunctionConfiguration.md) + [GetFunctionConfiguration](API_GetFunctionConfiguration.md) + [CreateFunction](API_CreateFunction.md) The following example AWS CLI command enables active tracing on a function named my\-function\. ``` $ aws lambda update-function-configuration --function-name my-function \ --tracing-config Mode=Active ``` Tracing mode is part of the version\-specific configuration that is locked when you publish a version of your function\. You can't change the tracing mode on a published version\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/python-tracing.md
37ce3af94d32-0
To enable active tracing on an `AWS::Lambda::Function` resource in an AWS CloudFormation template, use the `TracingConfig` property\. **Example [function\-inline\.yml](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/templates/function-inline.yml) – Tracing configuration** ``` Resources: function: Type: [AWS::Lambda::Function](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html) Properties: TracingConfig: Mode: Active ... ``` For an AWS Serverless Application Model \(AWS SAM\) `AWS::Serverless::Function` resource, use the `Tracing` property\. **Example [template\.yml](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/blank-nodejs/template.yml) – Tracing configuration** ``` Resources: function: Type: [AWS::Serverless::Function](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html) Properties: Tracing: Active
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/python-tracing.md
37ce3af94d32-1
Properties: Tracing: Active ... ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/python-tracing.md
7ca3979287e6-0
If you use the X\-Ray SDK to instrument AWS SDK clients your function code, your deployment package can become quite large\. To avoid uploading runtime dependencies every time you update your functions code, package them in a [Lambda layer](configuration-layers.md)\. The following example shows an `AWS::Serverless::LayerVersion` resource that stores X\-Ray SDK for Python\. **Example [template\.yml](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/blank-python/template.yml) – Dependencies layer** ``` Resources: function: Type: [AWS::Serverless::Function](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html) Properties: CodeUri: function/. Tracing: Active Layers: - !Ref libs ... libs: Type: [AWS::Serverless::LayerVersion](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-layerversion.html) Properties: LayerName: blank-python-lib Description: Dependencies for the blank-python sample app. ContentUri: package/. CompatibleRuntimes:
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/python-tracing.md
7ca3979287e6-1
Description: Dependencies for the blank-python sample app. ContentUri: package/. CompatibleRuntimes: - python3.8 ``` With this configuration, you only update library layer if you change your runtime dependencies\. The function deployment package only contains your code\. When you update your function code, upload time is much faster than if you include dependencies in the deployment package\. Creating a layer for dependencies requires build changes to generate the layer archive prior to deployment\. For a working example, see the [blank\-python](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-python) sample application\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/python-tracing.md
cba745b765ca-0
By default, IAM users and roles don't have permission to create or modify Lambda resources\. They also can't perform tasks using the AWS Management Console, AWS CLI, or AWS API\. An IAM administrator must create IAM policies that grant users and roles permission to perform specific API operations on the specified resources they need\. The administrator must then attach those policies to the IAM users or groups that require those permissions\. To learn how to create an IAM identity\-based policy using these example JSON policy documents, see [Creating policies on the JSON tab](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-json-editor) in the *IAM User Guide*\. **Topics** + [Policy best practices](#security_iam_service-with-iam-policy-best-practices) + [Using the Lambda console](#security_iam_id-based-policy-examples-console) + [Allow users to view their own permissions](#security_iam_id-based-policy-examples-view-own-permissions)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security_iam_id-based-policy-examples.md
6e90980de98f-0
Identity\-based policies are very powerful\. They determine whether someone can create, access, or delete Lambda resources in your account\. These actions can incur costs for your AWS account\. When you create or edit identity\-based policies, follow these guidelines and recommendations: + **Get Started Using AWS Managed Policies** – To start using Lambda quickly, use AWS managed policies to give your employees the permissions they need\. These policies are already available in your account and are maintained and updated by AWS\. For more information, see [Get Started Using Permissions With AWS Managed Policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#bp-use-aws-defined-policies) in the *IAM User Guide*\. + **Grant Least Privilege** – When you create custom policies, grant only the permissions required to perform a task\. Start with a minimum set of permissions and grant additional permissions as necessary\. Doing so is more secure than starting with permissions that are too lenient and then trying to tighten them later\. For more information, see [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege) in the *IAM User Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security_iam_id-based-policy-examples.md
6e90980de98f-1
+ **Enable MFA for Sensitive Operations** – For extra security, require IAM users to use multi\-factor authentication \(MFA\) to access sensitive resources or API operations\. For more information, see [Using Multi\-Factor Authentication \(MFA\) in AWS](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa.html) in the *IAM User Guide*\. + **Use Policy Conditions for Extra Security** – To the extent that it's practical, define the conditions under which your identity\-based policies allow access to a resource\. For example, you can write conditions to specify a range of allowable IP addresses that a request must come from\. You can also write conditions to allow requests only within a specified date or time range, or to require the use of SSL or MFA\. For more information, see [IAM JSON Policy Elements: Condition](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html) in the *IAM User Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security_iam_id-based-policy-examples.md
ebfefbf5db83-0
To access the AWS Lambda console, you must have a minimum set of permissions\. These permissions must allow you to list and view details about the Lambda resources in your AWS account\. If you create an identity\-based policy that is more restrictive than the minimum required permissions, the console won't function as intended for entities \(IAM users or roles\) with that policy\. For an example policy that grants minimal access for function development, see [Function development](access-control-identity-based.md#permissions-user-function)\. In addition to Lambda APIs, the Lambda console uses other services to display trigger configuration and let you add new triggers\. If your users use Lambda with other services, they need access to those services as well\. For details on configuring other services with Lambda, see [Using AWS Lambda with other services](lambda-services.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security_iam_id-based-policy-examples.md
6f912ae0393d-0
This example shows how you might create a policy that allows IAM users to view the inline and managed policies that are attached to their user identity\. This policy includes permissions to complete this action on the console or programmatically using the AWS CLI or AWS API\. ``` { "Version": "2012-10-17", "Statement": [ { "Sid": "ViewOwnUserInfo", "Effect": "Allow", "Action": [ "iam:GetUserPolicy", "iam:ListGroupsForUser", "iam:ListAttachedUserPolicies", "iam:ListUserPolicies", "iam:GetUser" ], "Resource": ["arn:aws:iam::*:user/${aws:username}"] }, { "Sid": "NavigateInConsole", "Effect": "Allow", "Action": [ "iam:GetGroupPolicy", "iam:GetPolicyVersion", "iam:GetPolicy", "iam:ListAttachedGroupPolicies", "iam:ListGroupPolicies", "iam:ListPolicyVersions",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security_iam_id-based-policy-examples.md
6f912ae0393d-1
"iam:ListGroupPolicies", "iam:ListPolicyVersions", "iam:ListPolicies", "iam:ListUsers" ], "Resource": "*" } ] } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security_iam_id-based-policy-examples.md
004cacc0236e-0
Concurrency is the number of requests that your function is serving at any given time\. When your function is invoked, Lambda allocates an instance of it to process the event\. When the function code finishes running, it can handle another request\. If the function is invoked again while a request is still being processed, another instance is allocated, which increases the function's concurrency\. Concurrency is subject to a Regional [quota](gettingstarted-limits.md) that is shared by all functions in a Region\. To ensure that a function can always reach a certain level of concurrency, you can configure the function with [reserved concurrency](#configuration-concurrency-reserved)\. When a function has reserved concurrency, no other function can use that concurrency\. Reserved concurrency also limits the maximum concurrency for the function, and applies to the function as a whole, including versions and aliases\. When Lambda allocates an instance of your function, the [runtime](lambda-runtimes.md) loads your function's code and runs initialization code that you define outside of the handler\. If your code and dependencies are large, or you create SDK clients during initialization, this process can take some time\. As your function [scales up](invocation-scaling.md), this causes the portion of requests that are served by new instances to have higher latency than the rest\. To enable your function to scale without fluctuations in latency, use [provisioned concurrency](#configuration-concurrency-provisioned)\. By allocating provisioned concurrency before an increase in invocations, you can ensure that all requests are served by initialized instances with very low latency\. You can configure provisioned concurrency on a version of a function, or on an alias\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
004cacc0236e-1
Lambda also integrates with [Application Auto Scaling](https://docs.aws.amazon.com/autoscaling/application/userguide/)\. You can configure Application Auto Scaling to manage provisioned concurrency on a schedule or based on utilization\. Use scheduled scaling to increase provisioned concurrency in anticipation of peak traffic\. To increase provisioned concurrency automatically as needed, use [the Application Auto Scaling API](#configuration-concurrency-api) to register a target and create a scaling policy\. Provisioned concurrency counts towards a function's reserved concurrency and Regional quotas\. If the amount of provisioned concurrency on a function's versions and aliases adds up to the function's reserved concurrency, all invocations run on provisioned concurrency\. This configuration also has the effect of throttling the unpublished version of the function \(`$LATEST`\), which prevents it from executing\. **Topics** + [Configuring reserved concurrency](#configuration-concurrency-reserved) + [Configuring provisioned concurrency](#configuration-concurrency-provisioned) + [Configuring concurrency with the Lambda API](#configuration-concurrency-api)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
abdec0e06602-0
To manage reserved concurrency settings for a function, use the Lambda console\. **To reserve concurrency for a function** 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose a function\. 1. Under **Concurrency**, choose **Edit**\. 1. Choose **Reserve concurrency**\. Enter the amount of concurrency to reserve for the function\. 1. Choose **Save**\. You can reserve up to the **Unreserved account concurrency** value that is shown, minus 100 for functions that don't have reserved concurrency\. To throttle a function, set the reserved concurrency to zero\. This stops any events from being processed until you remove the limit\. The following example shows two functions with pools of reserved concurrency, and the unreserved concurrency pool used by other functions\. Throttling errors occur when all of the concurrency in a pool is in use\. ![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency-reserved.png) **Legend** + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency.concurrency.png) Function concurrency
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
abdec0e06602-1
+ ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency.reserved.png) Reserved concurrency + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency.unreserved.png) Unreserved concurrency + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency.throttling.png) Throttling Reserving concurrency has the following effects\. + **Other functions can't prevent your function from scaling** – All of your account's functions in the same Region without reserved concurrency share the pool of unreserved concurrency\. Without reserved concurrency, other functions can use up all of the available concurrency\. This prevents your function from scaling up when needed\. + **Your function can't scale out of control** – Reserved concurrency also limits your function from using concurrency from the unreserved pool, which caps its maximum concurrency\. You can reserve concurrency to prevent your function from using all the available concurrency in the Region, or from overloading downstream resources\. Setting per\-function concurrency can impact the concurrency pool that is available to other functions\. To avoid issues, limit the number of users who can use the `PutFunctionConcurrency` and `DeleteFunctionConcurrency` API operations\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
9d591fd5518f-0
To manage provisioned concurrency settings for a version or alias, use the Lambda console\. **To reserve concurrency for an alias** 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose a function\. 1. Under **Provisioned concurrency configurations**, choose **Add**\. 1. Choose an alias or version\. 1. Enter the amount of provisioned concurrency to allocate\. 1. Choose **Save**\. You can manage provisioned concurrency for all aliases and versions from the function configuration page\. The list of provisioned concurrency configurations shows the allocation progress of each configuration\. Provisioned concurrency settings are also available on the configuration page for each version and alias\. In the following example, the `my-function-DEV` and `my-function-PROD` functions are configured with both reserved and provisioned concurrency\. For `my-function-DEV`, the full pool of reserved concurrency is also provisioned concurrency\. In this case, all invocations either run on provisioned concurrency or are throttled\. For `my-function-PROD`, a portion of the reserved concurrency pool is standard concurrency\. When all provisioned concurrency is in use, the function scales on standard concurrency to serve any additional requests\. ![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency-provisioned.png) **Legend**
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
9d591fd5518f-1
**Legend** + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency.concurrency.png) Function concurrency + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency.reserved.png) Reserved concurrency + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency.provisioned.png) Provisioned concurrency + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency.unreserved.png) Unreserved concurrency + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-concurrency.throttling.png) Throttling Provisioned concurrency does not come online immediately after you configure it\. Lambda starts allocating provisioned concurrency after a minute or two of preparation\. Similar to how functions [scale under load](invocation-scaling.md), up to 3000 instances of the function can be initialized at once, depending on the Region\. After the initial burst, instances are allocated at a steady rate of 500 per minute until the request is fulfilled\. When you request provisioned concurrency for multiple functions or versions of a function in the same Region, scaling quotas apply across all requests\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
9d591fd5518f-2
![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.png) **Legend** + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.instances.png) Function instances + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.open.png) Open requests + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.provisioned.png) Provisioned concurrency + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.standard.png) Standard concurrency
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
9d591fd5518f-3
Your function's [initialization code](gettingstarted-features.md#gettingstarted-features-programmingmodel) runs during allocation and every few hours, as running instances of your function are recycled\. You can see the initialization time in logs and [traces](services-xray.md) after an instance processes a request\. However, initialization is billed even if the instance never processes a request\. Provisioned concurrency runs continually and is billed separately from initialization and invocation costs\. For details, see [AWS Lambda pricing](https://aws.amazon.com/lambda/pricing/)\. Each version of a function can only have one provisioned concurrency configuration\. This can be directly on the version itself, or on an alias that points to the version\. Two aliases can't allocate provisioned concurrency for the same version\. Also, you can't allocate provisioned concurrency on an alias that points to the unpublished version \(`$LATEST`\)\. When you change the version that an alias points to, provisioned concurrency is deallocated from the old version and then allocated to the new version\. You can add a routing configuration to an alias that has provisioned concurrency\. However, you can't manage provisioned concurrency settings on the alias while the routing configuration is in place\. Lambda emits the following metrics for provisioned concurrency: **Provisioned concurrency metrics** + `ProvisionedConcurrentExecutions` + `ProvisionedConcurrencyInvocations` + `ProvisionedConcurrencySpilloverInvocations` + `ProvisionedConcurrencyUtilization`
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
9d591fd5518f-4
+ `ProvisionedConcurrencySpilloverInvocations` + `ProvisionedConcurrencyUtilization` For details, see [Working with AWS Lambda function metrics](monitoring-metrics.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
793558e1aacf-0
To manage concurrency settings and autoscaling with the AWS CLI or AWS SDK, use the following API operations\. + [PutFunctionConcurrency](API_PutFunctionConcurrency.md) + [GetFunctionConcurrency](https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunctionConcurrency.html) + [DeleteFunctionConcurrency](API_DeleteFunctionConcurrency.md) + [PutProvisionedConcurrencyConfig](https://docs.aws.amazon.com/lambda/latest/dg/API_PutProvisionedConcurrencyConfig.html) + [GetProvisionedConcurrencyConfig](https://docs.aws.amazon.com/lambda/latest/dg/API_GetProvisionedConcurrencyConfig.html) + [ListProvisionedConcurrencyConfigs](https://docs.aws.amazon.com/lambda/latest/dg/API_ListProvisionedConcurrencyConfigs.html) + [DeleteProvisionedConcurrencyConfig](https://docs.aws.amazon.com/lambda/latest/dg/API_DeleteProvisionedConcurrencyConfig.html) + [GetAccountSettings](API_GetAccountSettings.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
793558e1aacf-1
+ [GetAccountSettings](API_GetAccountSettings.md) + \(Application Auto Scaling\) [RegisterScalableTarget](https://docs.aws.amazon.com/autoscaling/application/APIReference/API_RegisterScalableTarget.html) + \(Application Auto Scaling\) [PutScalingPolicy](https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PutScalingPolicy.html) To configure reserved concurrency with the AWS CLI, use the `put-function-concurrency` command\. The following command reserves a concurrency of 100 for a function named `my-function`: ``` $ aws lambda put-function-concurrency --function-name my-function --reserved-concurrent-executions 100 { "ReservedConcurrentExecutions": 100 } ``` To allocate provisioned concurrency for a function, use `put-provisioned-concurrency-config`\. The following command allocates a concurrency of 100 for the `BLUE` alias of a function named `my-function`: ``` $ aws lambda put-provisioned-concurrency-config --function-name my-function \ --qualifier BLUE --provisioned-concurrent-executions 100 { "Requested ProvisionedConcurrentExecutions": 100,
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
793558e1aacf-2
--qualifier BLUE --provisioned-concurrent-executions 100 { "Requested ProvisionedConcurrentExecutions": 100, "Allocated ProvisionedConcurrentExecutions": 0, "Status": "IN_PROGRESS", "LastModified": "2019-11-21T19:32:12+0000" } ``` To configure Application Auto Scaling to manage provisioned concurrency, use the Application Auto Scaling to configure [target tracking scaling](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-target-tracking.html)\. First, register a function's alias as a scaling target\. The following example registers the `BLUE` alias of a function named `my-function`: ``` $ aws application-autoscaling register-scalable-target --service-namespace lambda \ --resource-id function:my-function:BLUE --min-capacity 1 --max-capacity 100 \ --scalable-dimension lambda:function:ProvisionedConcurrency ``` Next, apply a scaling policy to the target\. The following example configures Application Auto Scaling to adjust the provisioned concurrency configuration for an alias to keep utilization near 70 percent: ``` $ aws application-autoscaling put-scaling-policy --service-namespace lambda \
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
793558e1aacf-3
``` $ aws application-autoscaling put-scaling-policy --service-namespace lambda \ --scalable-dimension lambda:function:ProvisionedConcurrency --resource-id function:my-function:BLUE \ --policy-name my-policy --policy-type TargetTrackingScaling \ --target-tracking-scaling-policy-configuration '{ "TargetValue": 0.7, "PredefinedMetricSpecification": { "PredefinedMetricType": "LambdaProvisionedConcurrencyUtilization" }}' { "PolicyARN": "arn:aws:autoscaling:us-east-2:123456789012:scalingPolicy:12266dbb-1524-xmpl-a64e-9a0a34b996fa:resource/lambda/function:my-function:BLUE:policyName/my-policy", "Alarms": [ { "AlarmName": "TargetTracking-function:my-function:BLUE-AlarmHigh-aed0e274-xmpl-40fe-8cba-2e78f000c0a7", "AlarmARN": "arn:aws:cloudwatch:us-east-2:123456789012:alarm:TargetTracking-function:my-function:BLUE-AlarmHigh-aed0e274-xmpl-40fe-8cba-2e78f000c0a7"
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
793558e1aacf-4
}, { "AlarmName": "TargetTracking-function:my-function:BLUE-AlarmLow-7e1a928e-xmpl-4d2b-8c01-782321bc6f66", "AlarmARN": "arn:aws:cloudwatch:us-east-2:123456789012:alarm:TargetTracking-function:my-function:BLUE-AlarmLow-7e1a928e-xmpl-4d2b-8c01-782321bc6f66" } ] } ``` Application Auto Scaling creates two alarms in CloudWatch\. The first alarm triggers when the utilization of provisioned concurrency consistently exceeds 70 percent\. When this happens, Application Auto Scaling allocates more provisioned concurrency to reduce utilization\. The second alarm triggers when utilization is consistently less than 63 percent \(90 percent of the 70 percent target\)\. When this happens, Application Auto Scaling reduces the alias's provisioned concurrency\. In the following example, a function scales between a minimum and maximum amount of provisioned concurrency based on utilization\. When the number of open requests increases, Application Auto Scaling increases provisioned concurrency in large steps until it reaches the configured maximum\. The function continues to scale on standard concurrency until utilization starts to drop\. When utilization is consistently low, Application Auto Scaling decreases provisioned concurrency in smaller periodic steps\. ![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned-auto.png)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
793558e1aacf-5
**Legend** + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.instances.png) Function instances + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.open.png) Open requests + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.provisioned.png) Provisioned concurrency + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.standard.png) Standard concurrency To view your account's concurrency quotas in a Region, use `get-account-settings`\. ``` $ aws lambda get-account-settings { "AccountLimit": { "TotalCodeSize": 80530636800, "CodeSizeUnzipped": 262144000, "CodeSizeZipped": 52428800, "ConcurrentExecutions": 1000, "UnreservedConcurrentExecutions": 900 }, "AccountUsage": {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
793558e1aacf-6
"UnreservedConcurrentExecutions": 900 }, "AccountUsage": { "TotalCodeSize": 174913095, "FunctionCount": 52 } } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-concurrency.md
da328c4d47b4-0
This section contains the AWS Lambda API Reference documentation\. When making the API calls, you will need to authenticate your request by providing a signature\. AWS Lambda supports signature version 4\. For more information, see [Signature Version 4 signing process](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html) in the *Amazon Web Services General Reference*\. For an overview of the service, see [What is AWS Lambda?](welcome.md)\. You can use the AWS CLI to explore the AWS Lambda API\. This guide provides several tutorials that use the AWS CLI\. **Topics** + [Actions](API_Operations.md) + [Data Types](API_Types.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_Reference.md
8cd5fd96deb2-0
Because AWS SDKs use the CA certificates from your computer, changes to the certificates on the AWS servers can cause connection failures when you attempt to use an SDK\. You can prevent these failures by keeping your computer's CA certificates and operating system up\-to\-date\. If you encounter this issue in a corporate environment and do not manage your own computer, you might need to ask an administrator to assist with the update process\. The following list shows minimum operating system and Java versions: + Microsoft Windows versions that have updates from January 2005 or later installed contain at least one of the required CAs in their trust list\. + Mac OS X 10\.4 with Java for Mac OS X 10\.4 Release 5 \(February 2007\), Mac OS X 10\.5 \(October 2007\), and later versions contain at least one of the required CAs in their trust list\. + Red Hat Enterprise Linux 5 \(March 2007\), 6, and 7 and CentOS 5, 6, and 7 all contain at least one of the required CAs in their default trusted CA list\. + Java 1\.4\.2\_12 \(May 2006\), 5 Update 2 \(March 2005\), and all later versions, including Java 6 \(December 2006\), 7, and 8, contain at least one of the required CAs in their default trusted CA list\. When accessing the AWS Lambda management console or AWS Lambda API endpoints, whether through browsers or programmatically, you will need to ensure your client machines support any of the following CAs: + Amazon Root CA 1 + Starfield Services Root Certificate Authority \- G2 + Starfield Class 2 Certification Authority
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_Reference.md
8cd5fd96deb2-1
+ Amazon Root CA 1 + Starfield Services Root Certificate Authority \- G2 + Starfield Class 2 Certification Authority Root certificates from the first two authorities are available from [Amazon trust services](https://www.amazontrust.com/repository/), but keeping your computer up\-to\-date is the more straightforward solution\. To learn more about ACM\-provided certificates, see [AWS Certificate Manager FAQs\.](https://aws.amazon.com/certificate-manager/faqs/#certificates)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_Reference.md
8c3bd2462aa8-0
By default, Lambda runs your functions in an internal virtual private cloud \(VPC\) with connectivity to AWS services and the internet\. To access local network resources, you can [configure your function to connect to a VPC in your account](configuration-vpc.md)\. When you use this feature, you manage the function's internet access and network connectivity with VPC resources\. Network connectivity errors can result from issues in routing configuration, security group rules, role permissions, network address translation, or the availability of resources such as IP addresses or network interfaces\. They may result in a specific error or, if a request can't reach its destination, a timeout\. **Issue:** *Function loses internet access after connecting to a VPC* **Error:** *Error: connect ETIMEDOUT 176\.32\.98\.189:443* **Error:** *Error: Task timed out after 10\.00 seconds* When you connect a function to a VPC, all outbound requests go through your VPC\. To connect to the internet, configure your VPC to send outbound traffic from the function's subnet to a NAT gateway in a public subnet\. For more information and sample VPC configurations, see [Internet and service access for VPC\-connected functions](configuration-vpc.md#vpc-internet)\. **Issue:** *Function needs access to AWS services without using the internet*
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/troubleshooting-networking.md
8c3bd2462aa8-1
**Issue:** *Function needs access to AWS services without using the internet* To connect to AWS services from a private subnet with no internet access, use VPC endpoints\. For a sample template with VPC endpoints for DynamoDB and Amazon S3, see [Sample VPC configurations](configuration-vpc.md#vpc-samples)\. **Error:** *ENILimitReachedException: The elastic network interface limit was reached for the function's VPC\.* When you connect a function to a VPC, Lambda creates an elastic network interface for each combination of subnet and security group attached to the function\. These network interfaces are limited to 250 per VPC, but this limit can be increased\. To request an increase, use the [Support Center console](https://console.aws.amazon.com/support/v1#/case/create?issueType=service-limit-increase)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/troubleshooting-networking.md
2543602560ff-0
AWS CloudTrail is a service that provides a record of actions taken by a user, role, or an AWS service\. CloudTrail captures API calls as events\. For an ongoing record of events in your AWS account, you create a trail\. A trail enables CloudTrail to deliver log files of events to an Amazon S3 bucket\. You can take advantage of Amazon S3's bucket notification feature and direct Amazon S3 to publish object\-created events to AWS Lambda\. Whenever CloudTrail writes logs to your S3 bucket, Amazon S3 can then invoke your Lambda function by passing the Amazon S3 object\-created event as a parameter\. The S3 event provides information, including the bucket name and key name of the log object that CloudTrail created\. Your Lambda function code can read the log object and process the access records logged by CloudTrail\. For example, you might write Lambda function code to notify you if specific API call was made in your account\. In this scenario, CloudTrail writes access logs to your S3 bucket\. As for AWS Lambda, Amazon S3 is the event source so Amazon S3 publishes events to AWS Lambda and invokes your Lambda function\. **Example CloudTrail log** ``` { "Records":[ { "eventVersion":"1.02", "userIdentity":{ "type":"Root", "principalId":"123456789012",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail.md
2543602560ff-1
"type":"Root", "principalId":"123456789012", "arn":"arn:aws:iam::123456789012:root", "accountId":"123456789012", "accessKeyId":"access-key-id", "sessionContext":{ "attributes":{ "mfaAuthenticated":"false", "creationDate":"2015-01-24T22:41:54Z" } } }, "eventTime":"2015-01-24T23:26:50Z", "eventSource":"sns.amazonaws.com", "eventName":"CreateTopic", "awsRegion":"us-east-2", "sourceIPAddress":"205.251.233.176", "userAgent":"console.amazonaws.com", "requestParameters":{ "name":"dropmeplease" }, "responseElements":{ "topicArn":"arn:aws:sns:us-east-2:123456789012:exampletopic" },
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail.md
2543602560ff-2
}, "requestID":"3fdb7834-9079-557e-8ef2-350abc03536b", "eventID":"17b46459-dada-4278-b8e2-5a4ca9ff1a9c", "eventType":"AwsApiCall", "recipientAccountId":"123456789012" }, { "eventVersion":"1.02", "userIdentity":{ "type":"Root", "principalId":"123456789012", "arn":"arn:aws:iam::123456789012:root", "accountId":"123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "sessionContext":{ "attributes":{ "mfaAuthenticated":"false", "creationDate":"2015-01-24T22:41:54Z" } } }, "eventTime":"2015-01-24T23:27:02Z", "eventSource":"sns.amazonaws.com", "eventName":"GetTopicAttributes",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail.md
2543602560ff-3
"eventSource":"sns.amazonaws.com", "eventName":"GetTopicAttributes", "awsRegion":"us-east-2", "sourceIPAddress":"205.251.233.176", "userAgent":"console.amazonaws.com", "requestParameters":{ "topicArn":"arn:aws:sns:us-east-2:123456789012:exampletopic" }, "responseElements":null, "requestID":"4a0388f7-a0af-5df9-9587-c5c98c29cbec", "eventID":"ec5bb073-8fa1-4d45-b03c-f07b9fc9ea18", "eventType":"AwsApiCall", "recipientAccountId":"123456789012" } ] } ``` For detailed information about how to configure Amazon S3 as the event source, see [Using AWS Lambda with Amazon S3](with-s3.md)\. **Topics** + [Logging AWS Lambda API calls with AWS CloudTrail](logging-using-cloudtrail.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail.md
2543602560ff-4
**Topics** + [Logging AWS Lambda API calls with AWS CloudTrail](logging-using-cloudtrail.md) + [Tutorial: Triggering a Lambda function with AWS CloudTrail events](with-cloudtrail-example.md) + [Sample function code](with-cloudtrail-create-package.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail.md
58eee9c776da-0
The Error Processor sample application demonstrates the use of AWS Lambda to handle events from an [Amazon CloudWatch Logs subscription](services-cloudwatchlogs.md)\. CloudWatch Logs lets you invoke a Lambda function when a log entry matches a pattern\. The subscription in this application monitors the log group of a function for entries that contain the word `ERROR`\. It invokes a processor Lambda function in response\. The processor function retrieves the full log stream and trace data for the request that caused the error, and stores them for later use\. ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/sample-errorprocessor.png) Function code is available in the following files: + Random error – [random\-error/index\.js](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/error-processor/random-error/index.js) + Processor – [processor/index\.js](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/error-processor/processor/index.js)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-errorprocessor.md
58eee9c776da-1
You can deploy the sample in a few minutes with the AWS CLI and AWS CloudFormation\. To download, configure, and deploy it in your account, follow the instructions in the [README](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/error-processor)\. **Topics** + [Architecture and event structure](#sample-errorprocessor-architecture) + [Instrumentation with AWS X\-Ray](#sample-errorprocessor-instrumentation) + [AWS CloudFormation template and additional resources](#sample-errorprocessor-template)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-errorprocessor.md
296e7be6f5fb-0
The sample application uses the following AWS services\. + AWS Lambda – Runs function code, sends logs to CloudWatch Logs, and sends trace data to X\-Ray\. + Amazon CloudWatch Logs – Collects logs, and invokes a function when a log entry matches a filter pattern\. + AWS X\-Ray – Collects trace data, indexes traces for search, and generates a service map\. + Amazon Simple Storage Service \(Amazon S3\) – Stores deployment artifacts and application output\. Standard charges apply for each service\. A Lambda function in the application generates errors randomly\. When CloudWatch Logs detects the word `ERROR` in the function's logs, it sends an event to the processor function for processing\. **Example CloudWatch Logs message event** ``` { "awslogs": { "data": "H4sIAAAAAAAAAHWQT0/DMAzFv0vEkbLYcdJkt4qVXmCDteIAm1DbZKjS+kdpB0Jo350MhsQFyVLsZ+unl/fJWjeO5asrPgbH5..." } } ``` When it's decoded, the data contains details about the log event\. The function uses these details to identify the log stream, and parses the log message to get the ID of the request that caused the error\. **Example decoded CloudWatch Logs event data** ``` {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-errorprocessor.md
296e7be6f5fb-1
**Example decoded CloudWatch Logs event data** ``` { "messageType": "DATA_MESSAGE", "owner": "123456789012", "logGroup": "/aws/lambda/lambda-error-processor-randomerror-1GD4SSDNACNP4", "logStream": "2019/04/04/[$LATEST]63311769a9d742f19cedf8d2e38995b9", "subscriptionFilters": [ "lambda-error-processor-subscription-15OPDVQ59CG07" ], "logEvents": [ { "id": "34664632210239891980253245280462376874059932423703429141", "timestamp": 1554415868243, "message": "2019-04-04T22:11:08.243Z\t1d2c1444-efd1-43ec-b16e-8fb2d37508b8\tERROR\n" } ] } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-errorprocessor.md
296e7be6f5fb-2
} ] } ``` The processor function uses information from the CloudWatch Logs event to download the full log stream and X\-Ray trace for a request that caused an error\. It stores both in an Amazon S3 bucket\. To allow the log stream and trace time to finalize, the function waits for a short period of time before accessing the data\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-errorprocessor.md
dd0204e1ab7a-0
The application uses [AWS X\-Ray](services-xray.md) to trace function invocations and the calls that functions make to AWS services\. X\-Ray uses the trace data that it receives from functions to create a service map that helps you identify errors\. The following service map shows the random error function generating errors for some requests\. It also shows the processor function calling X\-Ray, CloudWatch Logs, and Amazon S3\. ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/sample-errorprocessor-servicemap.png) The two Node\.js functions are configured for active tracing in the template, and are instrumented with the AWS X\-Ray SDK for Node\.js in code\. With active tracing, Lambda tags adds a tracing header to incoming requests and sends a trace with timing details to X\-Ray\. Additionally, the random error function uses the X\-Ray SDK to record the request ID and user information in annotations\. The annotations are attached to the trace, and you can use them to locate the trace for a specific request\. ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/sample-errorprocessor-trace.png)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-errorprocessor.md
dd0204e1ab7a-1
The processor function gets the request ID from the CloudWatch Logs event, and uses the AWS SDK for JavaScript to search X\-Ray for that request\. It uses AWS SDK clients, which are instrumented with the X\-Ray SDK, to download the trace and log stream\. Then it stores them in the output bucket\. The X\-Ray SDK records these calls, and they appear as subsegments in the trace\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-errorprocessor.md
39ea5e1077c2-0
The application is implemented in two Node\.js modules and deployed with an AWS CloudFormation template and shell scripts\. The template creates the processor function, the random error function, and the following supporting resources\. + Execution role – An IAM role that grants the functions permission to access other AWS services\. + Primer function – An additional function that invokes the random error function to create a log group\. + Custom resource – An AWS CloudFormation custom resource that invokes the primer function during deployment to ensure that the log group exists\. + CloudWatch Logs subscription – A subscription for the log stream that triggers the processor function when the word ERROR is logged\. + Resource\-based policy – A permission statement on the processor function that allows CloudWatch Logs to invoke it\. + Amazon S3 bucket – A storage location for output from the processor function\. View the [application template](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/error-processor/template.yml) on GitHub\. ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/sample-errorprocessor-stack.png) To work around a limitation of Lambda's integration with AWS CloudFormation, the template creates an additional function that runs during deployments\. All Lambda functions come with a CloudWatch Logs log group that stores output from function executions\. However, the log group isn't created until the function is invoked for the first time\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-errorprocessor.md
39ea5e1077c2-1
To create the subscription, which depends on the existence of the log group, the application uses a third Lambda function to invoke the random error function\. The template includes the code for the primer function inline\. An AWS CloudFormation custom resource invokes it during deployment\. `DependsOn` properties ensure that the log stream and resource\-based policy are created prior to the subscription\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-errorprocessor.md
da05ae1ed133-0
You can build this application using [AWS SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/)\. To learn more about creating AWS SAM templates, see [ AWS SAM template basics](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html) in the *AWS Serverless Application Model Developer Guide*\. Below is a sample AWS SAM template for the Lambda application from the [tutorial](with-s3-example.md)\. Copy the text below to a \.yaml file and save it next to the ZIP package you created previously\. Note that the `Handler` and `Runtime` parameter values should match the ones you used when you created the function in the previous section\. **Example template\.yaml** ``` AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: CreateThumbnail: Type: [AWS::Serverless::Function](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html) Properties: Handler: handler Runtime: runtime Timeout: 60 Policies: AWSLambdaExecute Events: CreateThumbnailEvent: Type: S3
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-s3-example-use-app-spec.md
da05ae1ed133-1
Policies: AWSLambdaExecute Events: CreateThumbnailEvent: Type: S3 Properties: Bucket: !Ref SrcBucket Events: s3:ObjectCreated:* SrcBucket: Type: AWS::S3::Bucket ``` For information on how to package and deploy your serverless application using the package and deploy commands, see [Deploying serverless applications](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-deploying.html) in the *AWS Serverless Application Model Developer Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-s3-example-use-app-spec.md
81a02023f454-0
AWS Lambda provides [runtimes](lambda-runtimes.md) that run your function code in an Amazon Linux–based execution environment\. Lambda is responsible for keeping software in the runtime and execution environment up to date, releasing new runtimes for new languages and frameworks, and deprecating runtimes when the underlying software is no longer supported\. If you use additional libraries with your function, you're responsible for updating the libraries\. You can include additional libraries in the [deployment package](gettingstarted-features.md#gettingstarted-features-package), or in [layers](configuration-layers.md) that you attach to your function\. You can also build [custom runtimes](runtimes-custom.md) and use layers to share them with other accounts\. Lambda deprecates runtimes when the software on the runtime or its execution environment reaches end of life\. When Lambda deprecates a runtime, you're responsible for migrating your functions to a supported runtime for the same language or framework\. For details, see [Runtime support policy](runtime-support-policy.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security-configuration.md
c9a1bacc5461-0
An event source mapping is an AWS Lambda resource that reads from an event source and invokes a Lambda function\. You can use event source mappings to process items from a stream or queue in services that don't invoke Lambda functions directly\. Lambda provides event source mappings for the following services\. **Services that Lambda reads events from** + [Amazon DynamoDB](with-ddb.md) + [Amazon Kinesis](with-kinesis.md) + [Amazon Managed Streaming for Apache Kafka](with-msk.md) + [Amazon Simple Queue Service](with-sqs.md) An event source mapping uses permissions in the function's [execution role](lambda-intro-execution-role.md) to read and manage items in the event source\. Permissions, event structure, settings, and polling behavior vary by event source\. For more information, see the linked topic for the service that you use as an event source\. To manage event source mappings with the AWS CLI or AWS SDK, use the following API actions: + [CreateEventSourceMapping](API_CreateEventSourceMapping.md) + [ListEventSourceMappings](API_ListEventSourceMappings.md) + [GetEventSourceMapping](API_GetEventSourceMapping.md) + [UpdateEventSourceMapping](API_UpdateEventSourceMapping.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-eventsourcemapping.md
c9a1bacc5461-1
+ [UpdateEventSourceMapping](API_UpdateEventSourceMapping.md) + [DeleteEventSourceMapping](API_DeleteEventSourceMapping.md) The following example uses the AWS CLI to map a function named `my-function` to a DynamoDB stream that is specified by its Amazon Resource Name \(ARN\), with a batch size of 500\. ``` $ aws lambda create-event-source-mapping --function-name my-function --batch-size 500 --starting-position LATEST \ --event-source-arn arn:aws:dynamodb:us-east-2:123456789012:table/my-table/stream/2019-06-10T19:26:16.525 { "UUID": "14e0db71-5d35-4eb5-b481-8945cf9d10c2", "BatchSize": 500, "MaximumBatchingWindowInSeconds": 0, "ParallelizationFactor": 1, "EventSourceArn": "arn:aws:dynamodb:us-east-2:123456789012:table/my-table/stream/2019-06-10T19:26:16.525", "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-eventsourcemapping.md
c9a1bacc5461-2
"FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function", "LastModified": 1560209851.963, "LastProcessingResult": "No records processed", "State": "Creating", "StateTransitionReason": "User action", "DestinationConfig": {}, "MaximumRecordAgeInSeconds": 604800, "BisectBatchOnFunctionError": false, "MaximumRetryAttempts": 10000 } ``` Event source mappings read items from a stream or queue in batches\. They include multiple items in the event that your function receives\. You can configure the size of the batch that the event source mapping sends to your function, up to a maximum that varies by service\. The number of items in the event can be smaller than the batch size if there aren't enough items available, or if the batch is too large to send in one event and has to be split up\. The following example shows an event source mapping that reads from a Kinesis stream\. If a batch of events fails all processing attempts, the event source mapping sends details about the batch to an SQS queue\. ![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-eventsourcemapping.png)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-eventsourcemapping.md
c9a1bacc5461-3
The event batch is the event that Lambda sends to the function\. It is a batch of records or messages compiled from the items that the event source mapping reads from a stream or queue\. Batch size and other settings only apply to the event batch\. For streams, an event source mapping creates an iterator for each shard in the stream and processes items in each shard in order\. You can configure the event source mapping to read only new items that appear in the stream, or to start with older items\. Processed items aren't removed from the stream and can be processed by other functions or consumers\. By default, if your function returns an error, the entire batch is reprocessed until the function succeeds, or the items in the batch expire\. To ensure in\-order processing, processing for the affected shard is paused until the error is resolved\. You can configure the event source mapping to discard old events, restrict the number of retries, or process multiple batches in parallel\. If you process multiple batches in parallel, in\-order processing is still guaranteed for each partition key, but multiple partition keys in the same shard are processed simultaneously\. You can also configure the event source mapping to send an invocation record to another service when it discards an event batch\. Lambda supports the following [destinations](invocation-async.md#invocation-async-destinations) for event source mappings\. + **Amazon SQS** – An SQS queue\. + **Amazon SNS** – An SNS topic\. The invocation record contains details about the failed event batch in JSON format\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-eventsourcemapping.md
c9a1bacc5461-4
+ **Amazon SNS** – An SNS topic\. The invocation record contains details about the failed event batch in JSON format\. The following example shows an invocation record for a Kinesis stream\. **Example invocation Record** ``` { "requestContext": { "requestId": "c9b8fa9f-5a7f-xmpl-af9c-0c604cde93a5", "functionArn": "arn:aws:lambda:us-east-2:123456789012:function:myfunction", "condition": "RetryAttemptsExhausted", "approximateInvokeCount": 1 }, "responseContext": { "statusCode": 200, "executedVersion": "$LATEST", "functionError": "Unhandled" }, "version": "1.0", "timestamp": "2019-11-14T00:38:06.021Z", "KinesisBatchInfo": { "shardId": "shardId-000000000001", "startSequenceNumber": "49601189658422359378836298521827638475320189012309704722",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-eventsourcemapping.md
c9a1bacc5461-5
"endSequenceNumber": "49601189658422359378836298522902373528957594348623495186", "approximateArrivalOfFirstRecord": "2019-11-14T00:38:04.835Z", "approximateArrivalOfLastRecord": "2019-11-14T00:38:05.580Z", "batchSize": 500, "streamArn": "arn:aws:kinesis:us-east-2:123456789012:stream/mystream" } } ``` Lambda also supports in\-order processing for [FIFO \(first\-in, first\-out\) queues](with-sqs.md), scaling up to the number of active message groups\. For standard queues, items aren't necessarily processed in order\. Lambda scales up to process a standard queue as quickly as possible\. When an error occurs, batches are returned to the queue as individual items and might be processed in a different grouping than the original batch\. Occasionally, the event source mapping might receive the same item from the queue twice, even if no function error occurred\. Lambda deletes items from the queue after they're processed successfully\. You can configure the source queue to send items to a dead\-letter queue if they can't be processed\. For information about services that invoke Lambda functions directly, see [Using AWS Lambda with other services](lambda-services.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-eventsourcemapping.md
48c0152c3e27-0
You can create one or more aliases for your Lambda function\. A Lambda alias is like a pointer to a specific function version\. Users can access the function version using the alias Amazon Resource Name \(ARN\)\. **To create an alias** 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose the name of a function\. 1. On the function configuration page, choose **Actions**, **Create alias**\. ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/version-actions.png) 1. On the **Create alias** page, do the following: 1. Enter a **Name** for the alias\. 1. \(Optional\) Enter a **Description** for the alias\. 1. For **Version**, choose a function version that you want the alias to point to\. 1. \(Optional\) To configure routing on the alias, expand **Weighted alias**\. For more information, see [Alias routing configuration](#configuring-alias-routing)\. 1. Choose **Save**\. To view the aliases that are currently defined for a function, on the function configuration page, choose **Qualifiers**, and then choose the **Aliases** tab\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-aliases.md
769bd04eee48-0
To create an alias using the AWS Command Line Interface \(AWS CLI\), use the [https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/create-alias.html](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/create-alias.html) command\. ``` $ aws lambda create-alias --function-name my-function --name alias-name --function-version version-number --description " " ``` To change an alias to point a new version of the function, use the [https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/update-alias.html](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/update-alias.html) command\. ``` $ aws lambda update-alias --function-name my-function --name alias-name --function-version version-number ``` To delete an alias, use the [https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/delete-alias.html](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/delete-alias.html) command\. ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-aliases.md
769bd04eee48-1
``` $ aws lambda delete-alias --function-name my-function --name alias-name ``` The AWS CLI commands in the preceding steps correspond to the following Lambda API operations: + [CreateAlias](API_CreateAlias.md) + [UpdateAlias](API_UpdateAlias.md) + [DeleteAlias](API_DeleteAlias.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-aliases.md
288f8b305343-0
Each alias has a unique ARN\. An alias can point only to a function version, not to another alias\. You can update an alias to point to a new version of the function\. Event sources such as Amazon Simple Storage Service \(Amazon S3\) invoke your Lambda function\. These event sources maintain a mapping that identifies the function to invoke when events occur\. If you specify a Lambda function alias in the mapping configuration, you don't need to update the mapping when the function version changes\. For more information, see [AWS Lambda event source mappings](invocation-eventsourcemapping.md)\. In a resource policy, you can grant permissions for event sources to use your Lambda function\. If you specify an alias ARN in the policy, you don't need to update the policy when the function version changes\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-aliases.md
6b1765641d9d-0
You can use a [resource\-based policy](access-control-resource-based.md) to give a service, resource, or account access to your function\. The scope of that permission depends on whether you apply it to an alias, a version, or the entire function\. For example, if you use an alias name \(such as `helloworld:PROD`\), the permission allows you to invoke the `helloworld` function using the alias ARN \(`helloworld:PROD`\)\. If you attempt to invoke the function without an alias or a specific version, then you get a permission error\. This permission error still occurs even if you attempt to directly invoke the function version associated with the alias\. For example, the following AWS CLI command grants Amazon S3 permissions to invoke the PROD alias of the `helloworld` function when Amazon S3 is acting on behalf of `examplebucket`\. ``` $ aws lambda add-permission --function-name helloworld \ --qualifier PROD --statement-id 1 --principal s3.amazonaws.com --action lambda:InvokeFunction \ --source-arn arn:aws:s3:::examplebucket --source-account 123456789012 ``` For more information about using resource names in policies, see [Resources and conditions for Lambda actions](lambda-api-permissions-ref.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-aliases.md
77be73626bf9-0
Use routing configuration on an alias to send a portion of traffic to a second function version\. For example, you can reduce the risk of deploying a new version by configuring the alias to send most of the traffic to the existing version, and only a small percentage of traffic to the new version\. You can point an alias to a maximum of two Lambda function versions\. The versions must meet the following criteria: + Both versions must have the same [execution role](lambda-intro-execution-role.md)\. + Both versions must have the same [dead\-letter queue](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#dlq) configuration, or no dead\-letter queue configuration\. + Both versions must be published\. The alias cannot point to `$LATEST`\. **To configure routing on an alias** 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose the name of a function\. 1. Verify that the function has at least two published versions\. On the function configuration page, choose **Qualifiers**, and then choose the **Versions** tab to display the list of versions\. To create additional versions, follow the instructions in [Lambda function versions](configuration-versions.md)\. 1. Choose **Actions**, **Create alias**\. 1. On the **Create alias** page, do the following:
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-aliases.md
77be73626bf9-1
1. Choose **Actions**, **Create alias**\. 1. On the **Create alias** page, do the following: 1. Enter a **Name** for the alias\. 1. \(Optional\) Enter a **Description** for the alias\. 1. For **Version**, choose the first function version that you want the alias to point to\. 1. Expand **Weighted alias**\. 1. For **Additional version**, choose the second function version that you want the alias to point to\. 1. For **Weight \(%\)**, enter a weight value for the function\. *Weight* is the percentage of traffic that is assigned to that version when the alias is invoked\. The first version receives the residual weight\. For example, if you specify 10 percent to **Additional version**, the first version is assigned 90 percent automatically\. 1. Choose **Save**\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-aliases.md
142c15c01e29-0
Use the `create-alias` and `update-alias` AWS CLI commands to configure the traffic weights between two function versions\. When you create or update the alias, you specify the traffic weight in the `routing-config` parameter\. The following example creates a Lambda function alias named **routing\-alias** that points to version 1 of the function\. Version 2 of the function receives 3 percent of the traffic\. The remaining 97 percent of traffic is routed to version 1\. ``` $ aws lambda create-alias --name routing-alias --function-name my-function --function-version 1 \ --routing-config AdditionalVersionWeights={"2"=0.03} ``` Use the `update-alias` command to increase the percentage of incoming traffic to version 2\. In the following example, you increase the traffic to 5 percent\. ``` $ aws lambda update-alias --name routing-alias --function-name my-function \ --routing-config AdditionalVersionWeights={"2"=0.05} ``` To route all traffic to version 2, use the `update-alias` command to change the `function-version` property to point the alias to version 2\. The command also resets the routing configuration\. ``` $ aws lambda update-alias --name routing-alias --function-name my-function \ --function-version 2 --routing-config AdditionalVersionWeights={}
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-aliases.md
142c15c01e29-1
--function-version 2 --routing-config AdditionalVersionWeights={} ``` The AWS CLI commands in the preceding steps correspond to the following Lambda API operations: + [CreateAlias](API_CreateAlias.md) + [UpdateAlias](API_UpdateAlias.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-aliases.md
0ca8963a8fbb-0
When you configure traffic weights between two function versions, there are two ways to determine the Lambda function version that has been invoked: + **CloudWatch Logs** – Lambda automatically emits a `START` log entry that contains the invoked version ID to Amazon CloudWatch Logs for every function invocation\. The following is an example: `19:44:37 START RequestId: request id Version: $version ` For alias invocations, Lambda uses the `Executed Version` dimension to filter the metric data by the invoked version\. For more information, see [Working with AWS Lambda function metrics](monitoring-metrics.md)\. + **Response payload \(synchronous invocations\)** – Responses to synchronous function invocations include an `x-amz-executed-version` header to indicate which function version has been invoked\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-aliases.md
146a835792f2-0
You can configure Amazon S3 to publish events to AWS Lambda when AWS CloudTrail stores API call logs\. Your Lambda function can read the log object and process the access records logged by CloudTrail\. Use the following instructions to create a Lambda function that notifies you when a specific API call is made in your account\. The function processes notification events from Amazon S3, reads logs from a bucket, and publishes alerts through an Amazon SNS topic\. For this tutorial, you create: + A CloudTrail trail and an S3 bucket to save logs to\. + An Amazon SNS topic to publish alert notifications\. + An IAM user role with permissions to read items from an S3 bucket and write logs to Amazon CloudWatch\. + A Lambda function that processes CloudTrail logs and sends a notification whenever an Amazon SNS topic is created\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
dea15c076aa9-0
This tutorial assumes that you have some knowledge of basic Lambda operations and the Lambda console\. If you haven't already, follow the instructions in [Getting started with AWS Lambda](getting-started.md) to create your first Lambda function\. Before you begin, make sure that you have the following tools: + [Node\.js 8 with `npm`](https://nodejs.org/en/download/releases/)\. + The Bash shell\. For Linux and macOS, this is included by default\. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows\-integrated version of Ubuntu and Bash\. + [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
9fae7b689f95-0
When you create a trail, CloudTrail records the API calls in log files and stores them in Amazon S3\. A CloudTrail log is an unordered array of events in JSON format\. For each call to a supported API action, CloudTrail records information about the request and the entity that made it\. Log events include the action name, parameters, response values, and details about the requester\. **To create a trail** 1. Open the [**Trails** page of the CloudTrail console](https://console.aws.amazon.com/cloudtrail/home#/configuration)\. 1. Choose **Create trail**\. 1. For **Trail name**, enter a name\. 1. For **S3 bucket**, enter a name\. 1. Choose **Create**\. 1. Save the bucket Amazon Resource Name \(ARN\) to add it to the IAM execution role, which you create later\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
0a729b300155-0
Create an Amazon SNS topic to send out a notification when new object events have occurred\. **To create a topic** 1. Open the [**Topics** page of the Amazon SNS console](https://console.aws.amazon.com/sns/home#/topics)\. 1. Choose **Create topic**\. 1. For **Topic name**, enter a name\. 1. Choose **Create topic**\. 1. Record the topic ARN\. You will need it when you create the IAM execution role and Lambda function\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
15e3d94918ef-0
An [execution role](lambda-intro-execution-role.md) gives your function permission to access AWS resources\. Create an execution role that grants the function permission to access CloudWatch Logs, Amazon S3, and Amazon SNS\. **To create an execution role** 1. Open the [**Roles** page](https://console.aws.amazon.com/iam/home#/roles) of the IAM console\. 1. Choose **Create role**\. 1. Create a role with the following properties: + For **Trusted entity**, choose **Lambda**\. + For **Role name**, enter **lambda\-cloudtrail\-role**\. + For **Permissions**, create a custom policy with the following statements\. Replace the highlighted values with the names of your bucket and topic\. ``` { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:*" ], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": [ "s3:GetObject" ],
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
15e3d94918ef-1
"Effect": "Allow", "Action": [ "s3:GetObject" ], "Resource": "arn:aws:s3:::my-bucket/*" }, { "Effect": "Allow", "Action": [ "sns:Publish" ], "Resource": "arn:aws:sns:us-west-2:123456789012:my-topic" } ] } ``` 1. Record the role ARN\. You will need it when you create the Lambda function\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
344089e9a202-0
The following Lambda function processes CloudTrail logs, and sends a notification through Amazon SNS when a new Amazon SNS topic is created\. **To create the function** 1. Create a folder and give it a name that indicates that it's your Lambda function \(for example, *lambda\-cloudtrail*\)\. 1. In the folder, create a file named `index.js`\. 1. Paste the following code into `index.js`\. Replace the Amazon SNS topic ARN with the ARN that Amazon S3 created when you created the Amazon SNS topic\. ``` var aws = require('aws-sdk'); var zlib = require('zlib'); var async = require('async'); var EVENT_SOURCE_TO_TRACK = /sns.amazonaws.com/; var EVENT_NAME_TO_TRACK = /CreateTopic/; var DEFAULT_SNS_REGION = 'us-east-2'; var SNS_TOPIC_ARN = 'arn:aws:sns:us-west-2:123456789012:my-topic'; var s3 = new aws.S3(); var sns = new aws.SNS({ apiVersion: '2010-03-31', region: DEFAULT_SNS_REGION });
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
344089e9a202-1
apiVersion: '2010-03-31', region: DEFAULT_SNS_REGION }); exports.handler = function(event, context, callback) { var srcBucket = event.Records[0].s3.bucket.name; var srcKey = event.Records[0].s3.object.key; async.waterfall([ function fetchLogFromS3(next){ console.log('Fetching compressed log from S3...'); s3.getObject({ Bucket: srcBucket, Key: srcKey }, next); }, function uncompressLog(response, next){ console.log("Uncompressing log..."); zlib.gunzip(response.Body, next); }, function publishNotifications(jsonBuffer, next) { console.log('Filtering log...'); var json = jsonBuffer.toString(); console.log('CloudTrail JSON from S3:', json); var records; try { records = JSON.parse(json); } catch (err) { next('Unable to parse CloudTrail JSON: ' + err); return;
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
344089e9a202-2
} catch (err) { next('Unable to parse CloudTrail JSON: ' + err); return; } var matchingRecords = records .Records .filter(function(record) { return record.eventSource.match(EVENT_SOURCE_TO_TRACK) && record.eventName.match(EVENT_NAME_TO_TRACK); }); console.log('Publishing ' + matchingRecords.length + ' notification(s) in parallel...'); async.each( matchingRecords, function(record, publishComplete) { console.log('Publishing notification: ', record); sns.publish({ Message: 'Alert... SNS topic created: \n TopicARN=' + record.responseElements.topicArn + '\n\n' + JSON.stringify(record), TopicArn: SNS_TOPIC_ARN }, publishComplete); }, next ); } ], function (err) { if (err) { console.error('Failed to publish notifications: ', err); } else { console.log('Successfully published all notifications.'); }
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
344089e9a202-3
} else { console.log('Successfully published all notifications.'); } callback(null,"message"); }); }; ``` 1. In the *lambda\-cloudtrail* folder, run the following script\. It creates a `package-lock.json` file and a `node_modules` folder, which handle all dependencies\. ``` $ npm install async ``` 1. Run the following script to create a deployment package\. ``` $ zip -r function.zip . ``` 1. Create a Lambda function named CloudTrailEventProcessing with the `create-function` command by running the following script\. Make the indicated replacements\. ``` $ aws lambda create-function --function-name CloudTrailEventProcessing \ --zip-file fileb://function.zip --handler index.handler --runtime nodejs12.x --timeout 10 --memory-size 1024 \ --role arn:aws:iam::123456789012:role/lambda-cloudtrail-role ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
2c92a19863e6-0
The Lambda function's resource policy needs permissions to allow Amazon S3 to invoke the function\. **To give Amazon S3 permissions to invoke the function** 1. Run the following `add-permission` command\. Replace the ARN and account ID with your own\. ``` $ aws lambda add-permission --function-name CloudTrailEventProcessing \ --statement-id Id-1 --action "lambda:InvokeFunction" --principal s3.amazonaws.com \ --source-arn arn:aws:s3:::my-bucket \ --source-account 123456789012 ``` This command grants the Amazon S3 service principal \(`s3.amazonaws.com`\) permissions to perform the `lambda:InvokeFunction` action\. Invoke permissions are granted to Amazon S3 only if the following conditions are met: + CloudTrail stores a log object in the specified bucket\. + The bucket is owned by the specified AWS account\. If the bucket owner deletes a bucket, another AWS account can create a bucket with the same name\. This condition ensures that only the specified AWS account can invoke your Lambda function\. 1. To view the Lambda function's access policy, run the following `get-policy` command, and replace the function name\. ``` $ aws lambda get-policy --function-name function-name ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
7574df4994ae-0
To request that Amazon S3 publishes object\-created events to Lambda, add a notification configuration to the S3 bucket\. In the configuration, you specify the following: + Event type – Any event types that create objects\. + Lambda function – The Lambda function that you want Amazon S3 to invoke\. **To configure notifications** 1. Open the [Amazon S3 console](https://console.aws.amazon.com/s3)\. 1. Choose the source bucket\. 1. Choose **Properties**\. 1. Under **Events**, configure a notification with the following settings: + **Name** – **lambda\-trigger** + **Events** – **All object create events** + **Send to** – **Lambda function** + **Lambda** – **CloudTrailEventProcessing** When CloudTrail stores logs in the bucket, Amazon S3 sends an event to the function\. The event provides information, including the bucket name and key name of the log object that CloudTrail created\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-cloudtrail-example.md
0056c0750dc9-0
AWS Lambda automatically monitors Lambda functions on your behalf, reporting metrics through Amazon CloudWatch\. To help you troubleshoot failures in a function, Lambda logs all requests handled by your function and also automatically stores logs generated by your code through Amazon CloudWatch Logs\. You can insert logging statements into your code to help you validate that your code is working as expected\. Lambda automatically integrates with CloudWatch Logs and pushes all logs from your code to a CloudWatch Logs group associated with a Lambda function, which is named /aws/lambda/*<function name>*\. To learn more about log groups and accessing them through the CloudWatch console, see the [Monitoring system, application, and custom log files](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/WhatIsCloudWatchLogs.html) in the *Amazon CloudWatch User Guide*\. You can view logs for Lambda by using the Lambda console, the CloudWatch console, the AWS CLI, or the CloudWatch API\. The following procedure show you how to view the logs by using the Lambda console\. **Note** There is no additional charge for using Lambda logs; however, standard CloudWatch Logs charges apply\. For more information, see [CloudWatch pricing\.](https://aws.amazon.com/cloudwatch/pricing/) **To view logs using the Lambda console** 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose a function\. 1. Choose **Monitoring**\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/monitoring-cloudwatchlogs.md
0056c0750dc9-1
1. Choose a function\. 1. Choose **Monitoring**\. ![\[Events\]](http://docs.aws.amazon.com/lambda/latest/dg/images/metrics-functions-list.png)![\[Events\]](http://docs.aws.amazon.com/lambda/latest/dg/)![\[Events\]](http://docs.aws.amazon.com/lambda/latest/dg/) A graphical representation of the metrics for the Lambda function are shown\. 1. Choose **View logs in CloudWatch**\. Lambda uses your function's permissions to upload logs to CloudWatch Logs\. If you don't see logs in the console, check your [execution role permissions](lambda-intro-execution-role.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/monitoring-cloudwatchlogs.md
20c087beb463-0
Returns a function's [tags](https://docs.aws.amazon.com/lambda/latest/dg/tagging.html)\. You can also view tags with [GetFunction](API_GetFunction.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListTags.md
f5048fda1be3-0
``` GET /2017-03-31/tags/ARN HTTP/1.1 ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListTags.md
7036b8e5a009-0
The request uses the following URI parameters\. ** [ARN](#API_ListTags_RequestSyntax) ** <a name="SSS-ListTags-request-Resource"></a> The function's Amazon Resource Name \(ARN\)\. Pattern: `arn:(aws[a-zA-Z-]*)?:lambda:[a-z]{2}(-gov)?-[a-z]+-\d{1}:\d{12}:function:[a-zA-Z0-9-_]+(:(\$LATEST|[a-zA-Z0-9-_]+))?` Required: Yes
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListTags.md
cb9fec643a42-0
The request does not have a request body\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListTags.md
042a74665b36-0
``` HTTP/1.1 200 Content-type: application/json { "Tags": { "string" : "string" } } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListTags.md
50591d4f3cb1-0
If the action is successful, the service sends back an HTTP 200 response\. The following data is returned in JSON format by the service\. ** [Tags](#API_ListTags_ResponseSyntax) ** <a name="SSS-ListTags-response-Tags"></a> The function's tags\. Type: String to string map
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListTags.md
fdc57d9618e2-0
**InvalidParameterValueException** One of the parameters in the request is invalid\. HTTP Status Code: 400 **ResourceNotFoundException** The resource specified in the request does not exist\. HTTP Status Code: 404 **ServiceException** The AWS Lambda service encountered an internal error\. HTTP Status Code: 500 **TooManyRequestsException** The request throughput limit was exceeded\. HTTP Status Code: 429
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListTags.md
e83249d689f0-0
For more information about using this API in one of the language\-specific AWS SDKs, see the following: + [AWS Command Line Interface](https://docs.aws.amazon.com/goto/aws-cli/lambda-2015-03-31/ListTags) + [AWS SDK for \.NET](https://docs.aws.amazon.com/goto/DotNetSDKV3/lambda-2015-03-31/ListTags) + [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/ListTags) + [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/ListTags) + [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/ListTags) + [AWS SDK for JavaScript](https://docs.aws.amazon.com/goto/AWSJavaScriptSDK/lambda-2015-03-31/ListTags) + [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/lambda-2015-03-31/ListTags)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListTags.md
e83249d689f0-1
+ [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/lambda-2015-03-31/ListTags) + [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/ListTags)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListTags.md
c627e8c536b6-0
AWS Lambda supports resource\-based permissions policies for Lambda functions and layers\. Resource\-based policies let you grant usage permission to other AWS accounts on a per\-resource basis\. You also use a resource\-based policy to allow an AWS service to invoke your function on your behalf\. For Lambda functions, you can [grant an account permission](#permissions-resource-xaccountinvoke) to invoke or manage a function\. You can add multiple statements to grant access to several accounts, or let any account invoke your function\. You can also use the policy to [grant invoke permission to an AWS service](#permissions-resource-serviceinvoke) that invokes a function in response to activity in your account\. **To view a function's resource\-based policy** 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose a function\. 1. Choose **Permissions**\. 1. The resource\-based policy shows the permissions that are applied when another account or AWS service attempts to access the function\. The following example shows a statement that allows Amazon S3 to invoke a function named `my-function` for a bucket named `my-bucket` in account `123456789012`\. ![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/permissions-resourcebased.png)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-resource-based.md
c627e8c536b6-1
For Lambda layers, you can only use a resource\-based policy on a specific layer version, instead of the entire layer\. In addition to policies that grant permission to a single account or multiple accounts, for layers, you can also grant permission to all accounts in an organization\. **Note** You can only update resource\-based policies for Lambda resources within the scope of the [AddPermission](API_AddPermission.md) and [AddLayerVersionPermission](API_AddLayerVersionPermission.md) API actions\. Currently, you can't author policies for your Lambda resources in JSON, or use conditions that don't map to parameters for those actions\. Resource\-based policies apply to a single function, version, alias, or layer version\. They grant permission to one or more services and accounts\. For trusted accounts that you want to have access to multiple resources, or to use API actions that resource\-based policies don't support, you can use [cross\-account roles](access-control-identity-based.md)\. **Topics** + [Granting function access to AWS services](#permissions-resource-serviceinvoke) + [Granting function access to other accounts](#permissions-resource-xaccountinvoke) + [Granting layer access to other accounts](#permissions-resource-xaccountlayer) + [Cleaning up resource\-based policies](#permissions-resource-cleanup)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-resource-based.md
b2be8e34c5b5-0
When you [use an AWS service to invoke your function](lambda-services.md), you grant permission in a statement on a resource\-based policy\. You can apply the statement to the entire function to be invoked or managed, or limit the statement to a single version or alias\. **Note** When you add a trigger to your function with the Lambda console, the console updates the function's resource\-based policy to allow the service to invoke it\. To grant permissions to other accounts or services that aren't available in the Lambda console, you can use the AWS CLI\. Add a statement with the `add-permission` command\. The simplest resource\-based policy statement allows a service to invoke a function\. The following command grants Amazon SNS permission to invoke a function named `my-function`\. ``` $ aws lambda add-permission --function-name my-function --action lambda:InvokeFunction --statement-id sns \ --principal sns.amazonaws.com --output text {"Sid":"sns","Effect":"Allow","Principal":{"Service":"sns.amazonaws.com"},"Action":"lambda:InvokeFunction","Resource":"arn:aws:lambda:us-east-2:123456789012:function:my-function"} ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-resource-based.md
b2be8e34c5b5-1
``` This lets Amazon SNS call the `lambda:Invoke` API for the function, but it doesn't restrict the Amazon SNS topic that triggers the invocation\. To ensure that your function is only invoked by a specific resource, specify the Amazon Resource Name \(ARN\) of the resource with the `source-arn` option\. The following command only allows Amazon SNS to invoke the function for subscriptions to a topic named `my-topic`\. ``` $ aws lambda add-permission --function-name my-function --action lambda:InvokeFunction --statement-id sns-my-topic \ --principal sns.amazonaws.com --source-arn arn:aws:sns:us-east-2:123456789012:my-topic ``` Some services can invoke functions in other accounts\. If you specify a source ARN that has your account ID in it, that isn't an issue\. For Amazon S3, however, the source is a bucket whose ARN doesn't have an account ID in it\. It's possible that you could delete the bucket and another account could create a bucket with the same name\. Use the `account-id` option to ensure that only resources in your account can invoke the function\. ``` $ aws lambda add-permission --function-name my-function --action lambda:InvokeFunction --statement-id s3-account \
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-resource-based.md
b2be8e34c5b5-2
$ aws lambda add-permission --function-name my-function --action lambda:InvokeFunction --statement-id s3-account \ --principal s3.amazonaws.com --source-arn arn:aws:s3:::my-bucket-123456 --source-account 123456789012 ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-resource-based.md
51c3799bcd34-0
To grant permissions to another AWS account, specify the account ID as the `principal`\. The following example grants account `210987654321` permission to invoke `my-function` with the `prod` alias\. ``` $ aws lambda add-permission --function-name my-function:prod --statement-id xaccount --action lambda:InvokeFunction \ --principal 210987654321 --output text {"Sid":"xaccount","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::210987654321:root"},"Action":"lambda:InvokeFunction","Resource":"arn:aws:lambda:us-east-2:123456789012:function:my-function"} ``` The resource\-based policy grants permission for the other account to access the function, but doesn't allow users in that account to exceed their permissions\. Users in the other account must have the corresponding [user permissions](access-control-identity-based.md) to use the Lambda API\. To limit access to a user, group, or role in another account, specify the full ARN of the identity as the principal\. For example, `arn:aws:iam::123456789012:user/developer`\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-resource-based.md
51c3799bcd34-1
The [alias](configuration-aliases.md) limits which version the other account can invoke\. It requires the other account to include the alias in the function ARN\. ``` $ aws lambda invoke --function-name arn:aws:lambda:us-west-2:123456789012:function:my-function:prod out { "StatusCode": 200, "ExecutedVersion": "1" } ``` The function owner can then update the alias to point to a new version without the caller needing to change the way they invoke your function\. This ensures that the other account doesn't need to change its code to use the new version, and it only has permission to invoke the version of the function associated with the alias\. You can grant cross\-account access for most API actions that [operate on an existing function](lambda-api-permissions-ref.md#permissions-resources-function)\. For example, you could grant access to `lambda:ListAliases` to let an account get a list of aliases, or `lambda:GetFunction` to let them download your function code\. Add each permission separately, or use `lambda:*` to grant access to all actions for the specified function\. **Cross\-account APIs** Currently, Lambda doesn’t currently support cross\-account actions for all of its APIs via resource\-based policies\. The following APIs are supported: + [Invoke](API_Invoke.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-resource-based.md
51c3799bcd34-2
+ [Invoke](API_Invoke.md) + [GetFunction](API_GetFunction.md) + [GetFunctionConfiguration](API_GetFunctionConfiguration.md) + [UpdateFunctionCode](API_UpdateFunctionCode.md) + [DeleteFunction](API_DeleteFunction.md) + [PublishVersion](API_PublishVersion.md) + [ListVersionsByFunction](API_ListVersionsByFunction.md) + [CreateAlias](API_CreateAlias.md) + [GetAlias](API_GetAlias.md) + [ListAliases](API_ListAliases.md) + [UpdateAlias](API_UpdateAlias.md) + [DeleteAlias](API_DeleteAlias.md) + [GetPolicy](API_GetPolicy.md) + [PutFunctionConcurrency](API_PutFunctionConcurrency.md) + [DeleteFunctionConcurrency](API_DeleteFunctionConcurrency.md) + [ListTags](API_ListTags.md) + [TagResource](API_TagResource.md) + [UntagResource](API_UntagResource.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-resource-based.md
51c3799bcd34-3
+ [UntagResource](API_UntagResource.md) To grant other accounts permission for multiple functions, or for actions that don't operate on a function, we recommend that you use [IAM roles](access-control-identity-based.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-resource-based.md