Development Notes
  • Introduction
  • Programming Langauges
    • Java
      • Cache
      • Java Fundamentals
      • Multithreading & Concurrency
      • Spring Boot
        • Spring Security
        • Development tips
      • ORM
        • Mybatis
      • Implementation & Testing
    • Node.js
      • Asynchronous Execution
      • Node.js Notes
    • Python
      • Memo
  • Data Structure & Algorithm
  • Database
  • Design Pattern
  • AWS Notes
    • Services
      • API Gateway
      • CloudHSM
      • Compute & Load Balancing
        • Auto Scaling Group
        • EC2
        • ECS
        • ELB
        • Lambda
      • Data Engineering
        • Athena
        • Batch
        • EMR
        • IoT
        • Kinesis
        • Video Streaming
        • Quicksight
      • Deployment
        • CloudFormation
        • Code Deploy
        • Elastic Beanstalk
        • OpsWorks
        • SAM
        • SSM
      • ElasticSearch
      • Identity & Federation
        • Directory Service
        • IAM
        • Organizations
        • Resource Access Manager (RAM)
        • SSO
        • STS
      • KMS
      • Management Tools
        • Catalog
        • CloudTrail
        • CloudWatch
        • Config
        • Cost Allocation Tags
        • GuardDuty
        • Savings Plans
        • Trusted Advisor
        • X-Ray
      • Migration
        • Cloud Migration: The 6R
        • Disaster Recovery
        • DMS
        • VM Migrations
      • Networking
        • ACM
        • CloudFront
        • Direct Connect
        • EIP & ENI
        • Network Security
        • PrivateLink
        • Route53
        • VPC
        • VPN
      • Service Commnucation
        • Amazon MQ
        • SNS
        • SQS
        • Step Functions
        • SWF
      • Storage
        • Aurora
        • DynamoDB
        • EBS
        • EFS
        • ElastiCache
        • RDS
        • Redshift
        • S3
        • Storage Gateway
      • Other Services
        • Alexa for Business, Lex, Connect
        • AppStream 2.0
        • CloudSearch
        • Comprehend
        • Data Tools
        • Elastic Transcoder
        • Mechanical Turk
        • Rekognition
        • WorkDocs
        • WorkSpaces
    • Well Architect Framework
      • Security
      • Reliability
      • Performance Effeciency
      • Cost Optimization
      • Operational Excellence
    • Labs
      • Webserver Implementation
      • ELB Implementation
      • Auto-scaling Implementation
      • A 3-tier Architecture In VPC
  • Architecture
    • Security
  • Spark
    • Memo
  • Conference Notes
    • Notes of JCConf 2017
  • AI Notes
Powered by GitBook
On this page

Was this helpful?

  1. AWS Notes
  2. Services
  3. Compute & Load Balancing

Lambda

PreviousELBNextData Engineering

Last updated 4 years ago

Was this helpful?

Introduction

  • A serverless compute service to run your code

Feature

  • Support language: C#, Java, Node, Python, Javascript, etc.

  • Lamda is charged with request times, duration, used memory.

  • Limits:

    • RAM: 128 ~ 3G

      • RAM is linked to CPU allocation (cannot be set accrodingly)

      • 2 vCPU are allocated after 1.5G of RAM

    • Timeout: 15 minutes (Can break into sub executions but be careful with the latency.)

    • /tmp storage: 512 MB (can't process big files)

    • Councurrency execution: 1000 (differs by region, can be requested to increase).

    • If your code is too large to upload and can not break the code down

      • Consider deploying with Elastic BeanStalk.

  • Security

    • IAM Roles policy: for Lambda execution.

    • Resource-based policy: allow other accounts, services to invoke / manage the Lambda.

    • Networking

      • Sits in the AWS VPC (by default)

        • Can access publicly

        • Cannot link to resources in a private Subnet.

      • Can create within your VPC

        • To access a resource in a private Subnet, the Lambda must be created within the private Subnet and do:

          • Assign Security Group with outbound rule to the Lambda

          • Use a NAT if needs to have a public access.

          • Can attach VPC Endpoint to asscess S3 / DynamoDB without requiring an IGW to save cost.

        • Reasons of EC2ThrottledException:

          • ​Does not have sufficient subnet IPs / subnet ENIs.

  • Logging, monitoring and tracing

    • CloudWatch: trace logs, metrics. (Make sure the Lambda has execution role with CloudWatch privilege).

    • X-Ray:

      • Can help debug / trace the end-to-end latency.

      • Enable in Lambda configuration (runs the X-Ray daemon for you)

      • Use AWS SDK in Code

      • Ensure Lambda has correct IAM execution role.

  • Invocation

    • Synchronous: by CLI, SDK, API Gateway

      • Clients waiting for the response.

      • Handling exception by client side.

    • Asynchronous: like S3, SNS, CloudWatch events

      • When error, Lambda woud attempt for 3 retries. (so make sure the process is idempotent).

      • Can define a destination or DLQ (dead-letter queue, supports SNS, SQS, Lambda for failed processing).

    • (Poll model, by another Lambda to trigger your Lambda)

      • In-ordered services: Kinesis data streams, SQS FIFO, DynamoDB streams and SQS (not guarenteed in-ordered) are supported.

      • Lambda Event Source Mapping would do poll from the source and send to Lambda function in a batch way.

      • If Lambda returns an error, the entire batch is reprocessed until success.

        • Kinesis, DynamoDB streams: would stop processing later shards.

        • SQS FIFO: stop, unless a SQS DLQ has been defined.

  • Destinations (AWS suggests to replace DLQ)

    • Can configure to send result to a destination.

    • Asynchronous: can define destinations for successful and failed events to:

      • SQS

      • SNS

      • Lambda

      • EventBridge Bus

    • Event Source Mapping: for discarded event batches (only for failures).

      • SQS

      • SNS

  • Versions

    • When you work on a Lambda function, we work on $LATEST. When publish a Lambda, a version is created.

    • Versions

      • are immutable.

      • have increasing version numbers.

      • get their own ARN.

      • include their code and configurarion.

      • can be accessed.

    • Aliases are pointers to Lambda versions.

      • Aliases are mutable and have ARNs.

      • Aliases enable stable configuration of event triggers / destinations.

      • Deployment to shift alias can be supported with CodeDeploy strategies:

        • Linear: grow traffic every N minutes until 100%.

        • Canary: try X percent then 100%.

        • AllAtOnce: immediate.

      • Can create pre & post traffic hooks to check the health of Lambda.

      • Scenarios:

        • can define a dev, test etc to point to a Lambda version.

        • can enable blue / green deployment by assigning weights to point to different Lambda versions.

Event Source Mapping