AWS Hello World Lambda Function - abstracting language runtime & functions as the unit of scale
AWS Lambda was introduced in 2014, and it is a compute service that runs code in response to events and automatically manages the compute resources required by that code.
The purpose of Lambda, as opposed to AWS EC2, is to simplify building smaller, on-demand applications that are responsive to events and new information. AWS targets starting a Lambda instance within milliseconds of an event.
AWS Lambda was designed for use cases such as image upload, responding to website clicks or reacting to output from a connected device. AWS Lambda can also be used to automatically provision back-end services triggered by custom requests.
Unlike Amazon EC2, which is priced by the hour, AWS Lambda is metered in increments of 100 milliseconds.
- wiki - Amazon Lambda
- VMs:
Machines as the unit of scale
Abstracts the hardware - Containers:
Applications as the unit of scale
Abstracts the OS - Lambda:
Functions as the unit of scale
Abstracts the runtime language
Ref : Create a Hello World Lambda Function.
In this tutorial, we'll create a Hello World Lambda function using the AWS Lambda console.
Next, we manually invoke the Lambda function using a sample event data. AWS Lambda executes the Lambda function and returns results.
We then verify execution results, including the logs that our Lambda function created and various CloudWatch metrics.
We will use the hello-world-python blueprint.
Though it provides sample code in Python, the language used for the Lambda function does not matter, and we can create our own Lambda functions in any of the supported languages.
Most blueprints process events from specific event sources, such as Amazon S3, DynamoDB, or custom application.
For example, if we select an s3-get-object blueprint, it provides sample code that processes an object-created event published by Amazon S3 that Lambda receives as parameter.
Because we select a blueprint for this exercise, the console will have some of the configuration information prepopulated: it preconfigures Python 2.7 as the runtime, provides example code, identifies the handler in the code sample, and other configuration information such as memory and timeout.
We will also create an IAM role (referred as the execution role) with the necessary permissions that AWS Lambda can assume to invoke our Lambda function.
Open AWS Lambda console, and choose "Get Started Now".
Choose "Create a Lambda function" to go to the "Lambda" => "New function" page, and select "hello-world-python" blueprint.
For this hello-world-python, we do not configure a trigger and choose Next.
Runtime is Python 2.7, and it reads incoming event data and logs some of the information to CloudWatch.
"Handler" shows lambda_function.lambda_handler value.
It is the "filename.handler-function".
The console saves the sample code in the lambda_function.py file and in the code lambda_handler is the function name that receives the event as a parameter when the Lambda function is invoked.
Let's review the sample code:
- The console saves this code as lambda_handler.py. The console then zips the file, and uploads it to AWS Lambda creating our Lambda function.
- The sample code processes incoming events of the following form:
{ "key3": "value3", "key2": "value2", "key1": "value1" }
After creating the Lambda function, we invoke it using sample events of this form in the next section.
- Note the Handler* value. It is of the form python-file-name.handler-function.
- In Role*, choose Create new role from template(s).
- In Role name, type a name for the role.
- In Role templates, Lambda provides a list of optional templates that, should we select one, automatically creates the role with the requisite permissions attached to that policy. For a list of the Policy templates, see Policy Templates. For the purpose of this tutorial, we can leave this field blank because our Lambda function already has the basic execution permission it needs.
Next:
Choose Create Function to create a Lambda function.
The console saves the code into a file and then zips the file, which is the deployment package. The console then uploads the deployment package to AWS Lambda creating Lambda function.
The console shows the hello-world-python Lambda function, we can now perform various action including test the function:
The tabs in the console:
- Code - Shows the Lambda function code.
- Configuration - shows current function configuration and we can change the configuration as needed. After we change any configuration settings, we choose Save to save the updated configuration.
- Triggers - Shows any triggers we configured for this function.
- Monitoring - Provides various CloudWatch metrics for our Lambda function. In the next section, we invoke our hello-world-python Lambda function and review these metrics.
Follow the steps to invoke our Lambda function using the sample event data provided in the console.
- On the Lambda > Functions > HelloWorld page, choose "Test".
- In the Input test event page, choose Hello World from the Sample event template list. The following sample event template appears in the window.
We can change key and values in the sample JSON, but don't change the event structure.
If we do change any keys and values, we must update the sample code accordingly.
Choose Save and test. - AWS Lambda executes our function on our behalf. The handler in our Lambda function receives and then processes the sample event.
The Execution result section shows the execution status as succeeded and also shows the function execution results.
- Run the Lambda function a few times to gather some metrics that we can view in the next step.
- Choose the Monitoring tab to view the CloudWatch metrics for the Lambda function. This page shows four CloudWatch metrics.
AWS (Amazon Web Services)
- AWS : EKS (Elastic Container Service for Kubernetes)
- AWS : Creating a snapshot (cloning an image)
- AWS : Attaching Amazon EBS volume to an instance
- AWS : Adding swap space to an attached volume via mkswap and swapon
- AWS : Creating an EC2 instance and attaching Amazon EBS volume to the instance using Python boto module with User data
- AWS : Creating an instance to a new region by copying an AMI
- AWS : S3 (Simple Storage Service) 1
- AWS : S3 (Simple Storage Service) 2 - Creating and Deleting a Bucket
- AWS : S3 (Simple Storage Service) 3 - Bucket Versioning
- AWS : S3 (Simple Storage Service) 4 - Uploading a large file
- AWS : S3 (Simple Storage Service) 5 - Uploading folders/files recursively
- AWS : S3 (Simple Storage Service) 6 - Bucket Policy for File/Folder View/Download
- AWS : S3 (Simple Storage Service) 7 - How to Copy or Move Objects from one region to another
- AWS : S3 (Simple Storage Service) 8 - Archiving S3 Data to Glacier
- AWS : Creating a CloudFront distribution with an Amazon S3 origin
- AWS : Creating VPC with CloudFormation
- AWS : WAF (Web Application Firewall) with preconfigured CloudFormation template and Web ACL for CloudFront distribution
- AWS : CloudWatch & Logs with Lambda Function / S3
- AWS : Lambda Serverless Computing with EC2, CloudWatch Alarm, SNS
- AWS : Lambda and SNS - cross account
- AWS : CLI (Command Line Interface)
- AWS : CLI (ECS with ALB & autoscaling)
- AWS : ECS with cloudformation and json task definition
- AWS Application Load Balancer (ALB) and ECS with Flask app
- AWS : Load Balancing with HAProxy (High Availability Proxy)
- AWS : VirtualBox on EC2
- AWS : NTP setup on EC2
- AWS: jq with AWS
- AWS & OpenSSL : Creating / Installing a Server SSL Certificate
- AWS : OpenVPN Access Server 2 Install
- AWS : VPC (Virtual Private Cloud) 1 - netmask, subnets, default gateway, and CIDR
- AWS : VPC (Virtual Private Cloud) 2 - VPC Wizard
- AWS : VPC (Virtual Private Cloud) 3 - VPC Wizard with NAT
- DevOps / Sys Admin Q & A (VI) - AWS VPC setup (public/private subnets with NAT)
- AWS - OpenVPN Protocols : PPTP, L2TP/IPsec, and OpenVPN
- AWS : Autoscaling group (ASG)
- AWS : Setting up Autoscaling Alarms and Notifications via CLI and Cloudformation
- AWS : Adding a SSH User Account on Linux Instance
- AWS : Windows Servers - Remote Desktop Connections using RDP
- AWS : Scheduled stopping and starting an instance - python & cron
- AWS : Detecting stopped instance and sending an alert email using Mandrill smtp
- AWS : Elastic Beanstalk with NodeJS
- AWS : Elastic Beanstalk Inplace/Rolling Blue/Green Deploy
- AWS : Identity and Access Management (IAM) Roles for Amazon EC2
- AWS : Identity and Access Management (IAM) Policies, sts AssumeRole, and delegate access across AWS accounts
- AWS : Identity and Access Management (IAM) sts assume role via aws cli2
- AWS : Creating IAM Roles and associating them with EC2 Instances in CloudFormation
- AWS Identity and Access Management (IAM) Roles, SSO(Single Sign On), SAML(Security Assertion Markup Language), IdP(identity provider), STS(Security Token Service), and ADFS(Active Directory Federation Services)
- AWS : Amazon Route 53
- AWS : Amazon Route 53 - DNS (Domain Name Server) setup
- AWS : Amazon Route 53 - subdomain setup and virtual host on Nginx
- AWS Amazon Route 53 : Private Hosted Zone
- AWS : SNS (Simple Notification Service) example with ELB and CloudWatch
- AWS : Lambda with AWS CloudTrail
- AWS : SQS (Simple Queue Service) with NodeJS and AWS SDK
- AWS : Redshift data warehouse
- AWS : CloudFormation
- AWS : CloudFormation Bootstrap UserData/Metadata
- AWS : CloudFormation - Creating an ASG with rolling update
- AWS : Cloudformation Cross-stack reference
- AWS : OpsWorks
- AWS : Network Load Balancer (NLB) with Autoscaling group (ASG)
- AWS CodeDeploy : Deploy an Application from GitHub
- AWS EC2 Container Service (ECS)
- AWS EC2 Container Service (ECS) II
- AWS Hello World Lambda Function
- AWS Lambda Function Q & A
- AWS Node.js Lambda Function & API Gateway
- AWS API Gateway endpoint invoking Lambda function
- AWS API Gateway invoking Lambda function with Terraform
- AWS API Gateway invoking Lambda function with Terraform - Lambda Container
- Amazon Kinesis Streams
- AWS: Kinesis Data Firehose with Lambda and ElasticSearch
- Amazon DynamoDB
- Amazon DynamoDB with Lambda and CloudWatch
- Loading DynamoDB stream to AWS Elasticsearch service with Lambda
- Amazon ML (Machine Learning)
- Simple Systems Manager (SSM)
- AWS : RDS Connecting to a DB Instance Running the SQL Server Database Engine
- AWS : RDS Importing and Exporting SQL Server Data
- AWS : RDS PostgreSQL & pgAdmin III
- AWS : RDS PostgreSQL 2 - Creating/Deleting a Table
- AWS : MySQL Replication : Master-slave
- AWS : MySQL backup & restore
- AWS RDS : Cross-Region Read Replicas for MySQL and Snapshots for PostgreSQL
- AWS : Restoring Postgres on EC2 instance from S3 backup
- AWS : Q & A
- AWS : Security
- AWS : Security groups vs. network ACLs
- AWS : Scaling-Up
- AWS : Networking
- AWS : Single Sign-on (SSO) with Okta
- AWS : JIT (Just-in-Time) with Okta
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization