In this workshop, we will use the AWS Serverless Application Model (SAM) to write, deploy, and test functionality in our services. You do not need to have any experience with AWS SAM; The workshop will explain as we go on, so you can also learn how SAM helps you build a serverless system.
In this step we will create a Lambda function that, when called together, can be thought of as our Account Application service. Specifically, we will implement functions that will allow new registrations to be submitted (including a profile with name and address only), flag registrations for review, and mark registrations as approved or rejected. We’ll also add the ability to list all subscriptions in a certain state (like DEPOSTED or FLASHED) to avoid the hassle of checking the service’s datastore directly.
sudo passwd ec2-user
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# Then get brew into our $PATH
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
# Install the AWS SAM CLI
brew tap aws/tap
brew install aws-sam-cli
# Bootstrap our initial services into ./workshop-dir
git clone https://github.com/gabehollombe-aws/step-functions-workshop.git
cp -R step-functions-workshop/sam_template/ workshop-dir
# Change to our new directory
cd workshop-dir
The installation process will take a few minutes.
Sam build
# Run our first deploy in guided mode. Answer the interactive questions the same way that the comments show below:
sam deploy --guided
If you get an error in the deploy step, try replacing step 6 with the steps in Run sam deploy with self-created config file.
functions/account-applications/submit.js
# Lambda SubmitApplication function: find, flag, reject and approve registrations.
functions/account-applications/AccountApplications.js
# This is a generic file that provides CRUD operations for the **Account Application** data type. Used by other functions.
functions/data-checking/data-checking.js
# This file implements **DataChecking** Lambda function, its job is to handle name and address checking requests with some simple rules.
template.yaml
# This is the AWS SAM file that will declare the resources that we want to create and deploy in our solution, with a structure quite similar to the CloudFormation template because SAM is built on top of CloudFormation.
The next step is to test the sample services for our workflow.
Only do this step if sam deploy -guided fails.
aws s3 mb s3://stepfunctions-workshop-yourname --region ap-southeast-1
touch samconfig.toml
version=0.1
[default.global.parameters]
stack_name = "step-functions-workshop"
[default.deploy.parameters]
stack_name = "step-functions-workshop"
s3_bucket = "stepfunctions-workshop-yourname"
s3_prefix = "stepfunctions"
region = "ap-southeast-1"
confirm_changeset = false
capabilities = "CAPABILITY_IAM"
sam deploy