My new favorite way to trigger lambdas from Tulip

Previously I set up a private API gateway and then accessed it through a VPC Endpoint, this works but is a lot to setup.

Since we are using Aurora Postgres, you can actually execute a lambda from postgres.

So let’s say we had a lambda that sends an SMS, it would be pretty similar to the one used by the API gateway but you don’t need to use queryStringParameters. (It will need SNS IAM access)

Grant your rds-lambda-role permission to execute the lambda. Then you can call it from postgres like this

SELECT * FROM aws_lambda.invoke(aws_commons.create_lambda_function_arn('your_function', 'us-east-1'),
  "phone_number": "11111111111",
  "message": "hello from postgres"

Super neat!

To make it more user friendly you can make a postgres function to wrap it.

CREATE OR REPLACE FUNCTION public.send_sms(phone_number text, message text)
 RETURNS integer
 LANGUAGE plpgsql
AS $function$

  rows_affected int;
  create_json TEXT;
  response TEXT;
  err_context text;
RAISE INFO 'Started';	  
-- Create Json	  
	create_json row_to_json(t)
	   ) t;
SELECT into response payload FROM aws_lambda.invoke(aws_commons.create_lambda_function_arn('your_function', 'us-east-1'),

RAISE INFO 'response:%',response;

-- parse the response
select into response response::json->'response';
-- remove qutoes
select into response replace(response,'"','');

if response = 'sent' then 
	return 1;
	return 0;


Then to call it you simply need to use

select public.send_sms('11111111111','hello from postgres') as status

So then you use this from within Tulip like this

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s