16 - Serverless Overviews

RDS - Invoking Lambda & Event Notifications

awslambdardsauroraeventbridgesaa-c03

Overview

RDS and Aurora can invoke Lambda functions from inside the database instance in some cases. This lets you process data events happening within the database. It is supported, for example, by RDS for PostgreSQL and Aurora MySQL.

Example: a user inserts a row into a registration table, the database invokes a Lambda function, and the function sends a welcome email to the user.

Requirements

  • The setup is done from within the database by connecting to it, not from the AWS console.
  • The RDS instance invokes the function, so it needs network connectivity to Lambda: allow inbound traffic from the RDS instance to Lambda, via a public path, a NAT gateway, or VPC endpoints. (The transcript says "public interest" and "the Invoke", likely slips for public internet access.)
  • The DB instance needs a proper IAM policy with permission to invoke the Lambda function.

RDS invoking a Lambda function

New userinserts a row RDS or Aurorainvokes the function Lambdasends email Userwelcome Needs: network path (public, NAT gateway or VPC endpoints) and an IAM policy that lets the DB instance invoke the function Set up from inside the database, not from the console.
The database instance itself calls Lambda when data changes. Setup happens inside the database.

RDS Event Notifications

RDS event notifications are a different thing. They tell you about the database instance itself (for example when it was created or started). They give no information about the data inside the database.

Exam Trap

Event notifications do not carry data events. To react to data changes, use the Lambda invocation from the database.

You can subscribe to events about:

  • the DB instance
  • DB snapshots
  • parameter group
  • security group
  • proxy
  • custom engine version

Delivery is near real time, up to 5 minutes. Targets:

  • SNS, which can fan out to an SQS queue or a Lambda function.
  • EventBridge, which has many destinations, including a Lambda function.
Invoke Lambda from the DB RDS event notifications
Reports on Data events in tables Instance-level events (created, started, snapshots, etc.)
Configured Inside the database AWS (SNS / EventBridge)
Needs Network path + IAM policy on the DB instance Subscription

Questions & Answers

Q1: How do you run a Lambda when a row is inserted in RDS?

Answer:

Configure the database (RDS for PostgreSQL or Aurora MySQL) to invoke the Lambda function, with network access and an IAM policy.

Q2: Do RDS event notifications tell you about data changes?

Answer:

No. They report on the instance, snapshots, parameter group, security group, proxy and custom engine version, up to 5 minutes delay, via SNS or EventBridge.

Check yourself

Quiz

Flashcards

Click the card (or focus it), then use ← → to move and Space to flip.