How to deploy infinitely scalable applications to AWS in minutes with Up & Semaphore CI

TJ Holowaychuk
Dec 4, 2017 · 5 min read
Image for post
Image for post

Many Apex Up users have been asking about integration with continuous integration platforms, this post walks through staging and deploying Up to production using Semaphore CI.

Serverless Up applications typically deploy in a few seconds from a laptop, however with a poor network connection you may want to consider CI, not only to improve workflow and testing, but for the improved upload speed.

Semaphore is my CI of choice — it has a clean design, lets you easily encrypt the env variables, schedule timed builds, and doesn’t require you to litter your repositories with dotfiles. With that said as long as you can define environment variables, you can choose whichever CI platform you prefer.

The Application

For this example we’ll be deploying a minimal Koa Node.js application. Create a new repository in your GitHub, and add app.js with the following code:

You can add the dependencies via npm or yarn, whichever you prefer. Deploy the app to AWS and check out that glorious “Hello”:

Now let’s set up CI.

Setup

To get started in Semaphore, you’ll first need to create a new project:

Image for post
Image for post

And find the repository you created earlier in GitHub:

Image for post
Image for post

Now on to the good stuff — configuring the build!

Configuring the Jobs

One of the things I really like about Semaphore is that you don’t have to use dotfiles in your repository, simply define the jobs and commands required in the UI. If your use-case allows for it, you can even run jobs in parallel to speed things up.

The “Setup” job will install NPM packages for the application, adjust the owner of /usr/local/bin since this is where Up will be installed by default, and then finally install Up itself. Up is distributed as binaries, so this process takes only a few seconds.

You can define and re-order the commands, however, if you click “Edit Job” you can copy-and-paste the commands above as text. The second job in this case is used to deploy to development (up ).

Image for post
Image for post

In scenarios where you run into permission issues installing to /usr/local/bin, or simply prefer to avoid this, you may provide an install path with BINDIR:

Note that if you’re running Node.js using Up, you’ll want to specify 6.10.3, as this is the “native” version of Node.js supported by AWS Lambda.

Configuring your AWS Credentials

After the jobs are configured just select your branch and click “Start”.

Image for post
Image for post

The first thing you’ll see is that up fails! This is because we haven’t provided any AWS credentials, so Up doesn’t know where to deploy, and is not authorized to do so.

Image for post
Image for post

If you head over to the “Environment Variables” tab in the sidebar, you can add plain text or encrypted env vars. You’ll need two variables, the AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID . The first may be plain text, however the second should be encrypted, when in doubt, just encrypt.

Image for post
Image for post

Now when you perform a new build you should have a passing CI pipeline!

Image for post
Image for post

You can read more the options for AWS credentials in the Up documentation. Also make sure to never use your root credentials in external services such as CI.

Deploying to Production with Up Pro

The Pro version of Up is in early-access — only $10/mo with the discount for unlimited use in your organization — providing encrypted env variables, alerting, and more goodies soon!

After subscribing to Up Pro you’ll need to authenticate in order to install the Pro binary. Run the following command to copy the credentials to your clipboard.

Add a new encrypted environment variable named UP_CONFIG :

Image for post
Image for post

Next you’ll need to add up upgrade after the installation of Up, this will install the Pro version, as it detects UP_CONFIG . Note that the “Deploy” job has been changed to deploy to production rather than development. Changing this command allows you to map GIT branches to the various stages, so you can utilize CI for pushing to development, staging, or production.

Note you may upgrade to a specific version of Up via up upgrade -t 0.5.4 to “lock” the version.

Image for post
Image for post

Try changing the “Hello\n” string in app.js to “Hello from Semaphore CI\n” and push the commit to GitHub.

In a minute or less you should see the lovely leafy green of success! There is no remote build on the AWS side, once it’s green, your application is live and serving requests, in under a minute.

Image for post
Image for post

If deploying apps, apis, and sites to your own AWS account in a single command sounds helpful, take a look at Apex Up — and check out Semaphore CI for creating organization-wide continuous integration workflows.

EDIT: Note that with recent versions of Up you may also upgrade the binary in-place, as to avoid permission issues or changes to /usr/local/bin , and optionally pass a specific version to “pin” the version of Up Pro via -t x.x.x

I reached out to Semaphore CI and they offered to provide a 30% discount for the first 3 months to Up users, using the coupon “SEMAPHORE330”. Note that it’s redeemable until the 31st of December.

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