Setup AWS lambda beginner example with step by step guide
Beginner example for setting up an AWS Lambda function using the AWS Management Console:
- Log in to your AWS account and navigate to the AWS Management Console.
- Click on the “Lambda” service from the list of services.
- Click on the “Create Function” button.
- Choose the “Author from scratch” option.
- Give your function a name and choose the runtime for your function (e.g., Python, Node.js, etc.).
- In the “Function code” section, you can either write your function code directly in the console or upload a ZIP file containing your code.
- In the “Handler” field, specify the name of your function and the file name that contains your function code (e.g.,
my_function.handler
). - Under “Basic settings”, you can configure the memory and timeout for your function.
- Click on the “Create function” button to create your function.
Here’s an example code for a simple AWS Lambda function in Python:
import json
def lambda_handler(event, context):
# Your code goes here
message = "Hello, World!"
return {
'statusCode': 200,
'body': json.dumps(message)
}
This function simply returns a “Hello, World!” message as a JSON response with a status code of 200.
Once you’ve created and tested your function, you can trigger it using various events, such as API Gateway, S3 events, or AWS CloudWatch events.