Getting started with Lambda:
- Create a function using Lambda function and then invoke it
- You can create Lambda function using Lambda console, or Code Editor IDE on Lambda Console or using command line tools, AWS SDK’s. For AWS CLI you get access to Lambda API
- You can deploy code to Lambda using a zip file or container image.
- Create a Lambda function with default function code
- On Lambda console, choose create function
- Give all information such as name and language parameters
- Finally create function and then invoke it after configure test events and by clicking on TEST
- Lastly check the execution Results.
- Create a Lambda function as a container image
- Create a Project Directory lets assume cd /opt ( We are working on EC2 instance here)
- Create a node.js function or any language which ever suits you
- Create a Dockerfile
- Install software’s : sudo apt update npm docker.io awscli
- Create Package.json for dependencies by running npm init command
- Finally Build your Docker image , Push it to ECR and then finally create Lambda function using container images.
- Create Lambda function using AWS CLI * It uses Boto3 to connect with Lambda API & you need to have access to create role
- aws lambda create-function –function-name func1 –zip-file fileb://a.zip –handler index.handler –runtime nodejs12.x \ –role arn:aws:iam:::role/lambda-ex
|Function||It gets invoked to run your code. It process events|
|Qualifier||Specific Version of code or configuration|
|Execution Environment||It manages process and resource that are required for lambda|
|Deployments||Container Based or Zip|
|Runtime||It is Language specific like python, node.js|
|Extension||To integrate with other AWS services|
|Event||Its required by function to process the data|
|Trigger||Which Invokes Lambda|
Features of Lambda:
- Programming Model: Provides runtime for languages that it supports and can easily switch between frameworks
- Scaling: As per Requests it auto scales
- Concurrency Methods: It can help in defining the right number of requests as required.
- Asynchronous Invocation: Lambda function queues the event and return response right away else in case of synchronous invocation it waits for a response.
- Based on container rich tool as well. You can use docker commands to work with Lambda.
Permissions In Lambda:
Here we have created a very simple diagram to explain if AWS service wants to connect with Lambda or vice versa , have a look here.
Resource Based Policy : For Any user , group or any other Accounts want to access Lambda function you need Resource Based Policy
Lambda Execution role: For Lambda function to access other AWS services you need this role and by default there are permission boundary which prevents you to openly access everything( Modify according to need)