Lambda

Solution Architect Associate

Developer Associate

  • Function as a Service
  • Maximum runtime for a function is 15 minutes and have a maximum of 10GB of allocated memory
  • Compute service where you can upload your code and Lambda takes care of provisioning and managing servers that run the code
  • Run in response to events
  • If your Lambda function needs to make an AWS API call, you need to attach a role to it (know for the exam!!)
  • You can optionally define the VPC your Lambda runs in, but by default it will run in the default VPC
  • Defining the amount of available memory to the Lambda function will automatically allocate the amount of CPU your runtime gets as well (know for the exam!!)
  • Runtimes include NodeJS, Java, Python, C#, Go
    • You can also create your own runtime if you can’t use one of the supported runtimes
  • Priced on # of requests, first 1 million requests are free per month, $0.20 per 1 million requests thereafter
  • Also billed for duration
  • Lambda scales out, not up, automatically
  • Lambda functions are independent, 1 event = 1 function
  • Lambdas can trigger other Lambdas
  • AWS X-Ray can be used to debug Lambda
  • Lambda can do things globally, like backing up S3 buckets
  • You can pass in Environment variables to your Lambdas, allowing you to not have to hard code things specific to environments
  • You can execute a Lambda function via a public endpoint through an ALB or an API Gateway
    • For ALB, you also have to define the Lambda in a Target Group

Vesion Control w/ Lambda

  • When using versioning, you can publish one or more versions of your Lambda functions
  • Each Lambda function version has a unique ARN
  • After you publish a version, it is Immutable
  • Two types of ARNs
    • Qualified: Function ARN with the version suffix
    • Unqualified: Just name of function, no version suffix
  • Can also create aliases that point to particular versions. For example, prod vs. qa vs. dev
  • $LATEST will be applied to the latest version, and that version is the only one you can make changes to
  • Versions can be found in the Qualifiers dropdown on top of Lambda screen
  • Can split traffic using aliases for things like blue/green testing
    • You cannot split traffic to the $LATEST version, you need to create an alias to the latest and use the alias to split
    • For ALB, you can also enable Multi-Header values in the target group of the ALB. This allows you to conver headers and query parameters with the same name to be handled as an array.
      • Ex: if you have a url like http://example.com/path?name=foo&name=bar, it will put “foo” and “bar” into an array for that named parameter.

Lambda@Edge

  • Deploy lambda function to each region alongside your CDN, allows you to modify requests to the CDN
  • You can modify:
    • After CloudFront receives a request from a viewer (viewer request)
    • Before CloudFront sends a request to an origin (origin request)
    • After the origin responds (origin response)
    • Before sending a response to the viewer (viewer response)

Synchronous Invocations

  • Services like Cognito, AWS CLI, API Gateway, ALB utilize synchronous invocations (i.e. they wait for the function to respond)

Asynchronous Invocations

  • Services like S3, SNS, CloudWatch Events/EventBridge, CodeCommit, CodePipeline, CloudWatch Logs, SES, Config, IoT, IoT Events utilize asynchronous invocations
  • Events are placed in an internal event queue, will retry automatically on failures
    • First retry immediately, second after 1 minute, 3rd after 2 minutes
  • Make sure processing is idempotent
  • Can utilize a DLQ for failed processing
  • Function will return a 202 status code when you invoke it this way

EventBridge Integration

  • Can utilize EventBridge to setup CRON jobs to do things like execute Lambda functions on a repeating frequency