AWS Lambda allows you to run code without provisioning or managing servers. Here's an example Python Lambda function:
import json
def lambda_handler(event, context):
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
To deploy this function using the AWS CLI:
aws lambda create-function \
--function-name my-function \
--runtime python3.8 \
--role arn:aws:iam::123456789012:role/service-role/MyLambdaRole \
--handler lambda_function.lambda_handler \
--code S3Bucket=my-bucket-name,S3Key=my-function-code.zip