Create Your Own Wake-Up Call Service With AWS Pinpoint, Lambda and CDK

Cagdas Ozbey
TysonWorks
Published in
4 min readFeb 20, 2020

Wake-up call service is exactly what you would imagine, someone will call you to wake you up and make sure that you are awake. It is still a common practice in hotels where hotel employees will wake you up via phone call. In this tutorial, we are going to build our own version using AWS Pinpoint, Lambda and CDK.

If you haven’t heard the term CDK, it means Cloud Development Kit. It is a modern Infrastructure as a Code tool from AWS, it allows us to use common programming languages to provision cloud resources. We will be using AWS Pinpoint to make outbound phone calls, Lambda function to execute Pinpoint API call to initiate an outbound call and Cloudwatch Events to schedule our Lambda function to run once daily.

For this tutorial, you will need NodeJS, npm and previously set up AWS profile. Requesting a long code(phone number) will cost you 1$ if you choose US based phone number, the costs might vary for different countries.

We will be deploying two different CDK stacks separately. The reasoning behind is that we need to create a Pinpoint project first and then we need to manually request for a long code. A long code is a standard telephone number that our message is sent from. At the time writing this post, Pinpoint does not allow any API calls to request for a long code, so we have to do it manually.

Here, we are creating a basic Pinpoint project.

Next, we will be creating the main logic, a Lambda Function and the Cloudwatch scheduler. We will be passing necessary information via environment variables.

In order to deploy these stacks and provide the necessary information, we are going to use a few Javascript libraries to accomplish our goal.

Here is the deploy script.

Don’t forget to provide necessary values via .env file inside the root folder

To deploy our service, we need to install dependencies and run the deploy.js script.

# Install dependencies at the project root folder
npm install
# Run the deploy script
node deploy.js

After the Pinpoint stack creation, we will be prompted to enter a long code.

To get a long code, head over to Pinpoint Console, select the newly created Pinpoint Project and go to Settings/Sms and Voice and click Request long codes.

Next, choose the target country and leave the default selection for the call type(Transactional) and click Request long codes.

You should see a phone number after a successful request.

Using the proper format, enter the long code.

After that, the CallService Stack will be deployed. Once both stacks are deployed, head over to the Lambda console and give our new call service a try.

By now, you should receive a phone call from the number we’ve created earlier. Cloudwatch Events will invoke the same lambda function once daily (or schedule that we would set using .env file).

We also need a way to destroy the stacks once we are done with our call service.

The final project can be found here

Are you ready to enhance your AWS Cloud journey? Head over to our website and book a free consultation call.

--

--