Skip to content

Creating Lambda function using Python code questions

0

Hi re:Post,

Thank you for your time and help!

This question relates to another post's "Implementation Steps", Step 2.

https://repost.aws/questions/QU3H_boyruS6GPz2W5hmZuZQ/how-to-automate-daily-delete-snapshots-and-automate-daily-copy-snapshots-between-regions

ie:

" Implementation Steps: .... 2) Create the Lambda function using the code above"

Here is screenshot of some of the Python code: Enter image description here

At the "Create Lambda function" workflow -> Lambda > Functions > Create function

Question1: Which create option should I use? I am assuming it is "Author from scratch" option Enter image description here

But under that option, "Author from scratch", I do not find where to drop in the Python code for the Lambda function.

Question2: Where do I put the python code when creating this Lambda function? Enter image description here

Thanks!

Best Regards,

Donald

asked a year ago160 views

2 Answers
1
Accepted Answer

To create a Lambda function with Python code, you should follow these steps:

  1. For Question 1: Yes, you should select "Author from scratch" when creating your Lambda function.

  2. For Question 2: After creating the function with basic information, you'll be able to add your Python code. Here's the complete process:

a. Open the Lambda console and click "Create function" b. Select "Author from scratch" c. Fill in the basic information:

  • Function name: Enter a name for your function (e.g., "DeleteSnapshots")
  • Runtime: Choose Python 3.12 or Python 3.13 (depending on your preference)
  • Architecture: Leave as x86_64 d. Click "Create function" e. After the function is created, you'll be taken to the function configuration page where you can add your Python code in the code editor that appears.

The code editor will be displayed after the function is created, not during the initial creation step. This is where you can paste the Python code from the post you referenced.

If you're working with dependencies like boto3 (which is included in the Lambda Python runtime), you can use it directly in your code by adding import boto3 at the beginning of your function.
Sources
Building Lambda functions with Python - AWS Lambda
Create your first Lambda function - AWS Lambda
Create a serverless file-processing app - AWS Lambda

answered a year ago

AWS
SUPPORT ENGINEER

reviewed a year ago

0

Ahh of course, I should have realized the adding code part was after the Lambda function setup, "After creating the function with basic information, you'll be able to add your Python code. " Thanks!

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.