Creating serverless Slack commands in minutes with Go & Up

TJ Holowaychuk
Sep 11, 2017 · 3 min read
Image for post
Image for post

This post walks through the creation of a serverless Slack command written in Golang, and deployed to AWS Lambda in seconds with Up.

You’ll be creating a `/time <url>` command used to check how long a website takes to respond. Up uses your own AWS account. You can host a large number of custom apps for free while still utilizing the AWS free tier (1 million requests/m).

Check out the installation instructions as well if you’re new to Up.

Registering the Slack command

The first step is to create a Slack app, allowing you to register commands, among other things.

Image for post
Image for post

Once created, click “Slash commands” in the menu on the left, and register the command. You’ll need to keep this page open for a minute since we need a Request URL so Slack knows where to send requests.

Image for post
Image for post

Creating the Slack command

In your project’s directory create a file named . Make sure to replace with your AWS profile name (read more).

Now we need a little HTTP server to process the Slack command POST request. Create a file with the following net/http server.

Deploy it with .

NOTE : The first deploy may take roughly 60s to set up resources.

Image for post
Image for post

Now you need to grab the URL and paste it into the Slack command page so Slack knows where to send requests. Copy the command’s URL to the clipboard using:

Paste it in the Request URL field, then you’re good to give it a test run:

Image for post
Image for post

With any luck, you’ll see a Hello World response!

Image for post
Image for post

Performing the request

Slack sends a POST request with form inputs, otherwise known as (a tragically named mime type, turned standard-ish).

To access the form values, parse the form with the ParseForm() method. In this case all we need is the “text” field from r.Form, the parsed form.

Now that the request is portion is complete, import the package and wrap the request with and to record the request duration.

Deploy again with and immediately after the deploy you’re ready to test out the real version:

Image for post
Image for post

Two files and a few commands later, you’re done! Repeat for as many Slack commands as you need.

Testing locally

One of Up’s strengths is deploying traditional “vanilla” HTTP servers. This means there is nothing new to learn when testing on your machine, develop the app as you always would.

Here’s an example of this application tested via :

Hope that was helpful! Check out the documentation for more help, and follow on Twitter for updates and various software rants.

freeCodeCamp.org

This is no longer updated.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store