- https://docs.aws.amazon.com/lambda/latest/dg/welcome.html
- Serverless compute – lets you
run code without provisioning a server
- AWS provides server capacity automatically in the background with all health checks, security patch maintenance, logging, scaling code deploying included
- User has no control over the compute instance (server)s
- Pay for the compute time you consume
- AWS provides server capacity automatically in the background with all health checks, security patch maintenance, logging, scaling code deploying included
- User has no control over the compute instance (server)s
- Pay for the compute time you consume
- Lambda Function
§ Supported: Node.js, C#, Java, Python, Ruby, Go
- Event trigger
§ SNS
§ S3 or DynamoDB - changes in data
§ In response to HTTP request on API Gateway
§ API calls over AWS SDK (customer applications invoking code form outside of AWS)
§ Etc.
- Downstream resources
§ AWS service called by the function (DynamoDB, S3 etc)
- Log streams
§ Metrics sent to Cloud Watch
- AWS Serverless Application Mode – SAM
§ https://aws.amazon.com/serverless/sam/
§ Open-source framework for building serverless applications
§ Provides shorthand syntax to express functions, APIs, databases, and event source mappings. You can define the application you want and model it using YAML. SAM transforms and expands the SAM syntax into AWS CloudFormation syntax, enabling you to build serverless applications faster
- Memory - Can only specify the amount of memory required to run, no other resources
§ Min 128 MB to max 3008 MB in increments of 64 MB
§ Functions with memory > 1538 MB run on multiple CPU thread; need to build the code appropriately
- Max execution time
§ Max 900 sec; default is 3 sec; if need more – have your function trigger another function
§ Longer execution time = greater cost
- IAM role
§ Role and permission to be used by the function
- Handler name
§ Method in the code where Lambda begins execution
- Services can access - AWS and non-AWS service
§ AWS Services run in VPC – need to configure access to the explicitly as Lambda exists outside of VPC
§ Non-AWS service on EC2 or VPC
- Event->Source mappings
§ https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html
- Triggers
§ https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html
§ Services that invoke Lambda functions synchronously
§ Elastic Load Balancing (Application Load Balancer)
§ Amazon Cognito
§ Amazon Lex
§ Amazon Alexa
§ Amazon API Gateway
§ Amazon CloudFront (Lambda@Edge)
§ Amazon Kinesis Data Firehose
§ AWS Step Functions
§ Amazon Simple Storage Service Batch (S3)
§ Services that invoke Lambda functions asynchronously
§ Amazon Simple Storage Service (S3)
§ Amazon Simple Notification Service (SNS)
§ Amazon Simple Email Service
§ AWS CloudFormation
§ Amazon CloudWatch Logs
§ Amazon CloudWatch Events
§ AWS CodeCommit
§ AWS Config
§ AWS IoT
§ AWS IoT Events
§ AWS CodePipeline
- Scaling
§ Lambda will automatically be scaled based on demand
§ Concurrent Invocation Limit is soft, set on the account basis, default 1000
§ Function that processes non-stream-based (non-DynamoDB or non-Kinesis) events – each trigger is a distinct function invocation
§ Stream-based – each shard is a unit of invocation
- Versioning
§ https://docs.aws.amazon.com/lambda/latest/dg/configuration-versions.html
§ You can use versions to manage the deployment of your AWS Lambda functions. For example, you can publish a new version of a function for beta testing without affecting users of the stable production version. Can set up aliases to enhance the release process.
- X-Ray
§ AWS X-Ray helps developers analyze and debug production, distributed applications, such as those built using a microservices architecture.
- CloudTrail
§ CloudTrail can log all API calls made to Lambda and made by Lambda
§ Logs sent to S3 – incl. IPs that invoked the API, timestamps, etc.
Lambda@Edge
- Lambda@Edge is a feature of Amazon CloudFront that lets you run code closer to users of your application, which improves performance and reduces latency
- Allows for execution of Lambda functions that customize content delivered by CloudFront
- https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html
- Node.js functions are loaded onto us-east-1 (N-Virginia) region, AWS distributes and executes GLOBALLY
- Running code is closer to the user improves the experience and reduces latency
- Lambda@Edge can be triggered by four different types of CloudFront events:
§ Viewer Request – when CloudFront receives a request from Viewer
§ Origin Request – before CloudFront forwards the request to the Origin
§ Origin Response – when CloudFront receives a response from the origin
§ View Response - before CloudFront forwards the response to the Viewer
- Triggers – up to 4
- Use cases:
§ Serve two different versions of an image without creating redirects or changing the URL. Read the cookies in the viewer request and modify the request URL accordingly.
§ change the value of a response header based on the value of another header.
§ HTTP redirect
§ Authenticate users at different location
§ Return different version of
website content based on the requester device and location
No comments:
Post a Comment