Serverless AWS Exploration
Daily Standup
September 30, 2018
The below is a work in progress since I decided not to carry on down this path. This step-by-step pretty much follows the Serverless Getting Started guide but posting this anyway.
Prerequisites
You will need the serverless framework installed globally on your machine:
npm install -g serverless
You will need an AWS account that’s been set up with your credit card.
IMPORTANT NOTE: Using AWS services can lead to charges showing up on your credit card statement. Yes, most of this is free for 12 months or longer. Yes, you would need to make over a million calls or store GBs of data before seeing any charges. However to be on the safe side, if at any point during the testing phase of this application you want to ensure no charges will be made, you can run the command
serverless remove
to decommission all AWS services created by the framework. Make sure you back up any data or important settings before doing so.
Initial Serverless Application SetUp
Create a project folder
mkdir project1
Initiate a git repo
git init
Create a
README.md
file with the basic info and a.gitignore
file to hide the basic system files, then commit:touch README.md
touch .gitignore
git add .
git commit -m "Initial commit"Follow the serverless guidance on creating a new AWS IAM user with permissions the app will need, then add the credentials to serverless in the shell:
serverless config credentials --provider aws --key FDJHGFD/KEY*ID/SMDH<G --secret SF5JHKG5SHGFD/SECRET*ACCESS%KEY/DFMF
It should show this has been successful:
Serverless: Setting up AWS...
Serverless: Saving your AWS profile in "~/.aws/credentials"...
Serverless: Success! Your AWS access keys were stored under the "default" profile.Prepare the project for Node with
npm init
(you can add the flag-f
to skip the questionnaire and begin with a blankpackage.json
)Add
express
andserverless-http
:npm install --save express serverless-http
Add the barebones application to a new file
app.js
in the root directory:const serverless = require('serverless-http');
const express = require('express');
const app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
})
module.exports.handler = serverless(app);Set up the initial severless settings for deployment in a new file
serverless.yml
also in the root directory:service: my-express-application
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-east-1
functions:
app:
handler: app.handler
events:
- http: ANY /
- http: 'ANY {proxy+}'Note, there are additional options available for this config file.
Deploy the app with
sls deploy
. Thsi will take a while the first time, while serverless provisions several AWS services. At the end it will spit out an endpoint where you can view the deployed app. Voila!Add
.serverless
to the.gitignore
file. Commit all updates.
Add A Data Store
DynamoDB is the NoSQL database option in the AWS ecosystem. We can add this easily using the serverless framework.
1.
…decided not to complete this!