Building a Serverless Work Phone
Hey there! My name is Austin Miller, I am currently the founder of PagerTree. In this post I will show you how to build a work phone in 3 easy steps using serverless technologies.
Why have a serverless work phone?
- Save Money 💲 💲 💲 (only costs $12/year)
- Makes your business look professional 👌
- Get hands on with serverless technologies ⚡️
Resources
Here’s a list of the resources you need:
- The code — GitHub repo
- AWS + Twilio Accounts
- Up
Assumptions
I am going to assume that you can do the following. If you can’t, find a coder friend, buy them a beer 🍺 and ask them for some help 😅
- You can run commands from a terminal Mac or Linux
- You have an AWS & Twilio account setup
- You have already purchased a number from Twilio w/ voice capabilities
Step 1: Setup Your Environment
The first you’ll want to do is install Up. To do this you can run the following command in your terminal:
$ curl -sf https://up.apex.sh/install | sh
That should download and install Up for you. Verify it installed correctly by running:
$ up version
You should the the version printed. If you don’t, you’ll want to check out the installation docs for any troubleshooting.
Next, we’ll need to create an IAM user with access credentials. So in AWS, navigate to the IAM console. Then from the left nav bar, go to the Users tab.
Then click the add user button. Enter the following and click next.
- User name — up-workphone
- Access type — Programmatic access
On the set permissions screen, click the attach existing policies directly tab, and click the create policy button.
On the create policy screen, click the JSON tab, and paste the following:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"acm:*",
"cloudformation:Create*",
"cloudformation:Delete*",
"cloudformation:Describe*",
"cloudformation:ExecuteChangeSet",
"cloudformation:Update*",
"cloudfront:*",
"cloudwatch:*",
"ec2:*",
"ecs:*",
"events:*",
"iam:AttachRolePolicy",
"iam:CreatePolicy",
"iam:CreateRole",
"iam:DeleteRole",
"iam:DeleteRolePolicy",
"iam:GetRole",
"iam:PassRole",
"iam:PutRolePolicy",
"lambda:AddPermission",
"lambda:Create*",
"lambda:Delete*",
"lambda:Get*",
"lambda:InvokeFunction",
"lambda:List*",
"lambda:RemovePermission",
"lambda:Update*",
"logs:Create*",
"logs:Describe*",
"logs:FilterLogEvents",
"logs:Put*",
"logs:Test*",
"route53:*",
"route53domains:*",
"s3:*",
"ssm:*",
"sns:*"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "apigateway:*",
"Resource": "arn:aws:apigateway:*::/*"
}
]
}
Now click the review policy button. Give it a name (ex: up-policy) and click create policy.
Now go back to the add user tab, click the refresh button, and select the up-policy. Click next.
On the review screen, click the create user button.
If you did everything correctly, you should see a message showing success. Next copy the Access key ID and Secret access key to your AWS credential file ( ~/.aws/credentials
).
It should look like this:
[up-workphone]
aws_access_key_id = AKIAJQPDQOBY5S4X2IBQ
aws_secret_access_key = 2EiFiC8iCJjgJu+IbVZKxZKmOT8RAmR+LSrCvLS4
Make sure you keep those credential safe and private. I’ve only put these here as an example. 🔐
Hopefully, by now you have already cloned the Github repo; if you haven’t clone it now, then run the follwing:
cd office-phone-up
npm install
After that rename the file called up.example.json
to up.json
, then change line 3 to use the user profile we recently created up-workphone
.
Finally deploy the application using the following command 🚀:
$ up deploy production
On first run, it might take a minute or so because its creating all the resources for you. Subsequent deploys will only take a few seconds.
You should see a message showing it successfully deployed. Now run the following command:
up url -c -s production
That will copy the production API url to your clipboard (you’ll need this in the next section).
Step 2: Connect Twilio
Next we’ll want to configure the phone number you bought with Twilio.
Navigate to the phone numbers page and select the your number. Scroll down to the Voice & Fax section, and where it says A Call Comes In, paste the same url you copied in the previous step. ☎️
Similarly, in the section labeled messaging, paste the same url you copied earlier and append /sms to the url. 💬
Finally, click the save button.
Step 3: Test Run + Customization
Awesome! It’s now time to kick the tires and give your work phone a test run!
Using your mobile phone, call the number you purchased 📞. With any luck you should hear a voice say:
Hi! You’ve reached our headquarters. We are currently closed. Our hours of operation are Monday thru Friday 8 AM to 5 PM.
That’s pretty cool, but your business shouldn’t be closed all the time, and you probably want to forward your work phone to your personal phone. That leads us to our last step: customization.
Going back to our up.json
you’ll want to set a couple environment variables. In the section labeled environment
, we’ll want to make a couple additions.
"environment": {
"NUMBER": "+12345678901",
"TIMEZONE": "America/Los_Angeles",
"COMPANYNAME": "PagerTree",
},
The NUMBER
should be your mobile number. This is the number the work phone will forward incoming call and texts messages to. The TIMEZONE
should be one of the moment.js timezones. The COMPANYNAME
should be the name of your company.
The are a lot of other settings you can change, such as days and hours of operation. Take a look at config.js
for further customization. ⚡️
After you make any changes, don’t forget to re-deploy your application by running:
$ up deploy production
Congratulations
Congratulations! You’ve successfully created and deployed a work phone on the cheap using serverless technologies.
If you liked this article, please make sure to give it some claps! And if your in the market for a better on-call experience, make sure to checkout PagerTree.