You are currently viewing Modify A Lambda Function

Modify A Lambda Function

Modify A Lambda Function

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have created our 1st Lambda function using python in AWS console.

https://cloudaffaire.com/create-a-lambda-function/

In this blog post, we are going to modify this lambda function. We will also create a version and alias of the lambda function.

Modify A Lambda Function:

Step 1: Login to AWS console and navigate to ‘Lambda’.

Modify A Lambda Function

Step 2: Click on the function name.

Modify A Lambda Function

Step 3: From the ‘Actions’ click ‘Publish new version’.

Modify A Lambda Function

Step 4: Provide a version description and click ‘Publish’.

Modify A Lambda Function

Lambda function version 1 successfully created.

Modify A Lambda Function

Note: Only latest version of the function is editable.

Next, we will create an alias of this version.

Step 5: From ‘Actions’ click ‘Create alias’.

Modify A Lambda Function

Note: Currently we are in myfunction version1.

Step 6: Provide name, description and version details and click ‘Create’.

Modify A Lambda Function

Function alias successfully created.

Modify A Lambda Function

Next, we are going to modify the function definition to demonstrate logging and context. Select the latest version.

Modify A Lambda Function

Step 7: Navigate to function code section and replace function code with below code. Click ‘Save’ once done.

Note: We are writing a bunch of logs of function context using print and logger statement.

Next, we will invoke this lambda function manually using AWS CLI.

Step 8: Login to EC2 instance and execute the below command.

Note: You can also execute the previous version of the function by providing the version details. #aws lambda invoke –function-name myfunction:1 –log-type Tail outputfile.txt

You can view lambda logs under CloudWatch Logs section.

Modify A Lambda Function

Hope you have enjoyed this article. In the next blog post, we will modify this function and add a trigger to this function.

To get more details on Lambda, please refer below AWS documentation

https://docs.aws.amazon.com/lambda/index.html

Leave a Reply