Lambda
To increase performance keep connect or close statements outside of the handler, Place the connection in the global space or have login in program to check db connectivity before making connections
Lambda needs permission to be granted to write to CloudWatch logs , if no permission then nothing will be written to CloudWatch logs
If no logs are being written to CloudWatch logs lambda doesn’t not have permission to write logs
Most important ones are below 2
AWSLambdaBasicExecutionRole : write logs to CloudWatch
AWSXRayDaemonWriteAccess: upload trace data to X-Ray
Others include
AWSLambdaSQSQueueExecutionRole: read a message from SQS.
AWSLambdaVPCAccessExecutionRole: to manage elastic network interfaces to connect your function to VPC
CloudWatchLambdaInsightsExecutionRolePolicy: To write runtime metrics to CloudWatch Lambda Insights.
AWSLambdaDynamoDBExecutionRole: Read records from DynamoDB stream.
AWSLambdaKinesisExecutionRole: events from Kinesis data stream or consumer.
AWSLambdaMQExecutionRole: read records from an Amazon MQ broker.
AWSLambdaMSKExecutionRole: Permission to read records from Amazon MSK cluster.
You increase memory (128MB to 10GB in 1MB incr) to increase CPU, ( this increases cost)
Aliases
Pointer to a specific Lambda function version
Layers
A layer is just a ZIP archive that contains libraries, a custom runtime, or other dependencies
used to pull in additional code and content in the form of layers
Environment variables
Enable you to dynamically pass settings to your function code and libraries, without making changes to your code
Ex: Lambda function which will run in various environments such as DEV, TEST, UAT, and PROD , and call different API for different environments
Synchronous invocation
Wait for the function to process the event and return a response (StatusCode: 200)
Use cases : API Gateway, CloudFront
Asynchronous invocation
Lambda queues the event for processing and returns a response immediately and without additional information (StatusCode: 202)
use the invoke command with --invocation-type parameter to Event
Use cases: S3 , SNS
HTTP Status Code: 429 ( or 502): TooManyRequestsException ,
Exceeded allowed concurrency , throttling occurs with 429
The request throughput limit was exceeded 🡺 for Synchronous invocations.
Asynchronous invocation 🡺 retry, then to DLQ (Dead letter Queue)
HTTP Status Code 504 (5XX)
INTEGRATION_FAILURE, INTEGRATION_TIMEOUT
INTEGRATION_TIMEOUT range is 50 milliseconds to 29 seconds
InvalidParameterValueException
one of the parameters in the request is invalid, ex: if you provided an IAM role in the CreateFunction API which AWS Lambda is unable to assume IAM role
Unzipped package is bigger than allotted size
CodeStorageExceededException
exceeded your maximum total code size per account
ResourceConflictException
resource already exists
ServiceException
AWS Lambda service encountered an internal error