DevOps
Cloud Infrastructure
Amazon Web Services
Lambda Practical: Deploying & Triggering

Lambda Practical: Deploying & Triggering

Learn by doing. In this walkthrough, you will create a serverless Python function that automatically triggers every time a file is uploaded to an S3 bucket.


🏗️ Phase 1: Creating Your First Function

  1. Log in to the AWS Management Console (opens in a new tab).
  2. Search for Lambda and click Create function.
  3. Select Author from scratch.

Step 1: Basic Information

  • Function name: process-s3-upload
  • Runtime: Python 3.12 (or latest)
  • Architecture: x86_64

Step 2: Permissions

  • Expand Change default execution role.
  • Select Create a new role with basic Lambda permissions.
  • This allows the function to upload logs to CloudWatch.
  1. Click Create function.

🧪 Phase 2: Testing the Logic

Before connecting triggers, verify that your code works using a mock event.

  1. In the Code tab, click the Test button.
  2. Select Create new event.
  3. Event name: test-upload.
  4. Keep the default JSON and click Save.
  5. Click Test again.
  6. Verify the Execution results:
    • Status: Succeeded
    • Output: "Hello from Lambda!"

🚀 Phase 3: Adding an S3 Trigger

Now, let's make the function reactive.

  1. In the Function overview section, click + Add trigger.
  2. Select S3 from the dropdown.
  3. Bucket: Select an existing bucket (or create one in a new tab).
  4. Event type: All object create events.
  5. Check the recursive search acknowledgment and click Add.

The visual architecture should now look like this:


🕵️ Phase 4: Monitoring in Cloudwatch

  1. Go to the Monitor tab of your function.
  2. Click View CloudWatch logs.
  3. Click on the latest Log stream.
  4. You will see every execution of your function, including the print() statements and errors.

🧹 Phase 5: Cleanup

To avoid any potential charges:

  1. Delete the Lambda function.
  2. Delete the IAM role created for the function (found in the IAM dashboard).
  3. If you created a test S3 bucket, delete it.

[!IMPORTANT] Why do we need a Role? A Lambda function cannot "do" anything outside itself unless it has a Role attached. By default, it can't even write logs. Always ensure your function's role has the necessary policies (e.g., S3ReadOnlyAccess) before trying to interact with other AWS services.