Lab Information
The Nautilus DevOps team continues to explore serverless architecture by setting up another Lambda function. This time, the task must be completed using the AWS Console to familiarize the team with the web interface. The function will return a custom greeting and demonstrate the capabilities of AWS Lambda effectively.
Create Python Script: Create a Python script named lambda_function.py with a function that returns the body Welcome to KKE AWS Labs! and status code 200.
Zip the Python Script: Zip the script into a file named function.zip.
Create Lambda Function: Create a Lambda function named xfusion-lambda-cli using the zipped file and specify Python as the runtime.
IAM Role: Use the IAM role named lambda_execution_role.
Use AWS CLI which is already configured on the aws-client host.
Lab Solutions
πΉ Step 1: Create the Python script
On the aws-client host, run:
cat << 'EOF' > lambda_function.py
def lambda_handler(event, context):
return {
"statusCode": 200,
"body": "Welcome to KKE AWS Labs!"
}
EOF
Verify the file:
cat lambda_function.py
πΉ Step 2: Zip the Python script
zip function.zip lambda_function.py
# Verify:
ls -l function.zip
πΉ Step 3: Get the IAM role ARN
You must use the existing role lambda_execution_role.
Run:
aws iam get-role \
--role-name lambda_execution_role \
--query "Role.Arn" \
--output text
π Copy the ARN (youβll use it in the next command).
πΉ Step 4: Create the Lambda function using the zip file
aws lambda create-function \
--function-name xfusion-lambda-cli \
--runtime python3.9 \
--role arn:aws:iam::831788756997:role/lambda_execution_role \
--handler lambda_function.lambda_handler \
--zip-file fileb://function.zip
β If successful, AWS will return a JSON output with function details.
πΉ Step 5: Verify the Lambda function (optional but recommended)
Invoke the function:
aws lambda invoke \
--function-name xfusion-lambda-cli \
response.json
Check the response:
β
Expected output:
{
"statusCode": 200,
"body": "Welcome to KKE AWS Labs!"
}
Top comments (0)