SVS308 R - AWS Serverless Developer Experience A Day in The Life of A Developer

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SVS308-R

AWS serverless developer experience:


A day in the life of a developer
Stephen Liedig (he/him) Tomas Mihalyi (he/him)
Principal Serverless Specialist Solutions Architect Serverless Specialist (Enterprise Support)
Amazon Web Services Amazon Web Services

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What you will learn today
In the first 20 minutes
• A crash course on the AWS Serverless Application
Model (AWS SAM)
• An overview of the Unicorn Properties architecture

In the remaining 100 minutes


Choose your own adventure
• Pick your runtime (Python, TypeScript, Java, .NET)
• We have 3 services, you choose 1 or more services
to build, in any order

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Before we get started
Make sure you have disconnected your mobile device from the
re:Invent Wi-Fi network

We assume you have a laptop and are familiar with either


Python, TypeScript, Java or .NET

This workshop is intended to be run over 4 hours; we do not


expect you to finish it in the allotted time; this workshop is
publicly available

If you need assistance, please raise your hand and one of our
friendly workshop developers will come and assist you

Have fun

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Why we created this workshop
Provide you with hands-on experience using the AWS
SAM and AWS SAM CLI
Introduce you tools, utilities, and development
practices that can make you a productive serverless
developer
Showcase how you can apply serverless application
integration patterns, event-driven architectures, and
orchestration using a real world architecture

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS SAM crash course

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS SAM comes in two parts

AWS SAM transform AWS SAM CLI


Shorthand syntax to express resources Provides tooling for local development,
and event source mappings, it provides debugging, build, packaging, and
infrastructure as code (IaC) for deployment for serverless applications
serverless applications

For example We’ll be covering these extensively in


MyDDBTable: the workshop
Type: AWS::Serverless::SimpleTable

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS SAM serverless resources

8
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::HttpApi
AWS::Serverless::SimpleTable
AWS::Serverless::LayerVersion
serverless
AWS::Serverless::Application
resource types
AWS::Serverless::StateMachine
AWS::Serverless::Connector New
SAM Version 2016-10-31

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lambda function event sources

17
• Amazon S3 • Amazon EventBridge
rule
• Amazon SNS
• Amazon CloudWatch
• Amazon Kinesis Logs
• Amazon DynamoDB • AWS IoT rule

function event • Amazon SQS • Amazon Alexa skill

source types • Amazon API Gateway • Amazon Cognito


Scheduled
supported in SAM • • Amazon MSK
• Amazon CloudWatch • Self-managed Apache
Events Kafka
• Amazon MQ
© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
SAM serverless resources – IAM policies

76
Policy template Description

CloudWatchPutMetricPolicy Gives permission to send metrics to CloudWatch


Gives create, read, update, and delete permissions to an Amazon
DynamoDBCrudPolicy DynamoDB table

EcsRunTaskPolicy Gives permission to start a new task for a task definition


managed templates Gives permission to mount an Amazon EFS file system with write
EFSWriteAccessPolicy access
with more being added
EventBridgePutEventsPolicy Gives permissions to send events to EventBridge

KinesisStreamReadPolicy Gives permission to list and read an Amazon Kinesis stream


Start here
RekognitionDetectOnlyPolicy Gives permission to detect faces, labels, and text

s12d.com/sam-policies S3FullAccessPolicy
Gives full access permission to act on the objects in an Amazon
S3 bucket
Gives read-only permission to read objects in an Amazon S3
S3ReadPolicy bucket
Gives write permission to write objects into an Amazon S3
S3WritePolicy bucket

SNSPublishMessagePolicy Gives permission to publish a message to an Amazon SNS topic


© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Example of AWS::Serverless::Function

In 24 lines of code, you can define


• Source code location
• Runtime
• Memory allocation
• Tracing
• Function permissions
• Define environment variables
• Event source trigger
• A REST API
• And more

This can be further simplified through


the Globals sections
© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS SAM CLI

• CLI tool for local development, debugging, testing, deploying, and monitoring
of serverless applications
• Supports API Gateway proxy-style and Lambda service API testing
• Response object and function logs available on your local machine
• Uses open-source docker-lambda images to mimic Lambda’s execution
environment such as timeout, memory limits, runtimes
• Tails production logs from CloudWatch logs
• Helps you build in native dependencies

https://s12d.com/sam

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
SAM CLI commands
• init Init an AWS SAM application
• build Build your Lambda Function code
• local Run your serverless function locally
• deploy Deploy an AWS SAM application
• delete Delete an application and the artifacts created by ‘sam deploy’
• logs Fetch logs for a function
• traces Fetch AWS X-Ray traces
• sync Sync a project to AWS
• pipeline Manage the continuous delivery of the application
• package Package an AWS SAM application
• validate Validate an AWS SAM template (tip: use the --debug flag to see transformed template)

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The workshop

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Introducing Unicorn Properties

Our use case is based on a real estate company


called Unicorn Properties

As a real estate agency, Unicorn Properties needs to


1. manage the publication of new property listings

2. manage contracts linked to individual properties

3. provide a way for their customers to view


approved property listings

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The architecture
WHAT YOU WILL BUILD TODAY

Unicorn Contracts
Unicorn.Cont ract s
1

Cont ract s
t able

Agent Cont ract s API Cont ract s Cont ract st at us changed Cont ract st at us Propert y
funct ion event handler t able approvals sync
Paramet er St ore

Unicorn Propert y Publishing Cont ract st at us Wait for contract


Propert ies Approval workflow checker approval
event bus
Propert ies Publicat ion
SendTaskSuccess
t able evaluat ion event
handler

Propert y images
S3 bucket Unicorn.Propert ies
Cust omer
Search

Propert ies
Web API
funct ion
3 Unicorn Properties
Agent
Approval

Unicorn Properties Web


funct ion
2
Unicorn.Web

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The architecture
BUILDING THE CONTRACTS SERVICE

• There is a 1:1 relationship


Unicorn.Cont ract s between properties and
contracts

Cont ract s
• Contracts and properties are
t able Amazon Event Bridge correlated by the Property ID
Cont ract st at us
changed event Unicorn Propert ies event bus • The Property ID is the
properties address formatted
as a unique string:
Agent Cont ract s API Cont ract s
funct ion
Cont ract s regist ry

“usa/anytown/main-street/111”

• Publish the
ContractStatusChanged
event and create a schema

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The architecture
BUILDING THE PROPERTIES WEB

• Properties web responsible for


allowing customers to search
Amazon EventBridge
and view property listings
Publicat ion
Evaluat ion
Complet ed event
Unicorn Propert ies event bus • Only approved listings can be
Propert ies Publicat ion approved Publicat ion approval request ed event
displayed
t able event handler
Publicat ion evaluat ion complet ed event
• Agents request approval for
specified property
Cust omer Cont ract s regist ry
Search

Publication approval requested


funct ion
Propert ies Publicat ion approval Propert ies regist ry •
Web API request ed event
event triggers approval
Agent
Approval workflow
funct ion

Unicorn.Web Propert y images • Approval outcome is handled by


S3 bucket
publication approved event

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The architecture
BUILDING THE PROPERTIES SERVICE

• Properties service primarily


responsible for approving
property listings for the web
Cont ract st at us Cont ract st at us
changed event st ream
• Properties service maintains a
Amazon EventBridge
Cont ract st at us changed Cont ract st at us Propert y
local copy of contract status. No
event handler t able approvals sync direct dependency on Contract
Unicorn Propert ies event bus
service or it’s data
Cont ract St at us Changed

Propert y Approval Request ed

Property approvals sync function


Cont ract st at us Wait for contract

Propert y Publishing
Approval workflow checker approval
Publicat ion

Cont ract s regist ry


evaluat ion
complet ed event
handles DynamoDB stream
SendTaskSuccess events; it determines whether or
Propert ies regist ry not to pass AWS Step Function
Unicorn.Propert ies task token back to the state
machine based on the contract
state

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The architecture
THE PROPERTIES SERVICE WORKFLOW

• A contract is required to approve


listing

• Checks content sentiment and


unsafe images; all checks must
pass for the listing to be made
public

• Wait state checks to see if the


contract in an APPROVED state
before completing the workflow;
task token stored against the
property’s contract state

• Publish Publication Evaluation


Completed event – approved or
declined

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Choose your own runtime

Python TypeScript Java C#

s12d.com/aws-sde-python s12d.com/aws-sde-ts s12d.com/aws-sde-java s12d.com/aws-sde-dotnet

Supported by fully functional reference architectures

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Tools you’ll be using

AWS Lambda Powertools AWS Lambda Power Tuning


A suite of utilities for AWS Lambda functions An open-source tool that can help you visualize
that makes distributed tracing, structured and fine tune the memory/power configuration
logging, custom metrics, idempotency, and
of Lambda functions
many leading practices easier s12d.com/lambda-power-tuning
s12d.com/powertools-[py | ts | java | dotnet]

cfn-lint and serverless rules mhlabs utilities


Validate AWS CloudFormation yaml/json Tools and libraries built and maintained
templates against the AWS CloudFormation by Mathem tech team
resource specification; includes checking valid
values for resource properties and best practices https://github.com/mhlabs
for serverless applications

s12d.com/serverless-rules

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Serverless CI/CD
AWS SAM PIPELINES

AWS SAM Pipelines generates resource and configuration required to build a


continuous integration and continuous delivery (CI/CD) pipeline
Supports AWS CodePipeline, Jenkins, GitHub Actions, and GitLab CI/CD

+ + +
AWS Cloud9 AWS CodeCommit AWS CodePipeline AWS CodeBuild

AWS SAM Pipelines


© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Serverless CI/CD
OUR DEPLOYMENT PHILOSOPHY

3 4 uni-prop-dev-contracts

1 New commit triggered


uni-prop-prod-contracts
Cont ract s Service

2
Pipeline
Parameter Store Filter CodeCommit events

uni-prop-dev-properties
5 3 Query last commit ID

Trigger funct ion uni-prop-prod-properties


User AWS CodeCommit Amazon Event Bridge Propert ies Service
default event bus Pipeline 4 Query pipeline ARN for each
1 2 changed directory

uni-prop-dev-properties-web
5 Trigger appropriate pipeline

Propert ies Web


uni-prop-prod-properties-web
Pipeline

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Let’s get started

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Getting started with this workshop

• As a participant, you will have access to an AWS account with any optional pre-
provisioned infrastructure and IAM policies needed to complete this workshop

• The AWS account will only be available for the duration of this workshop; you
will lose access to the account thereafter

• The optional pre-provisioned infrastructure will be deployed to a specific


Region; check your workshop content to determine whether other Regions will
be used

• Be sure to review the terms and conditions of the event; do not upload any
personal or confidential information in the account

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Step 1: Sign in via your preferred method

https://catalog.workshops.aws/join

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Step 2: Enter event access code

Enter 12-digit event access code; if you were given a one-click join link, you can
skip this step

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Step 3: Review terms and join event

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Step 4: Access AWS account

Access the AWS Console or generate AWS CLI credentials as needed

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Step 5: Get started with the workshop

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thank you!
Stephen Liedig Tomas Mihalyi
@sliedigaws tomas-mihalyi-0762a392

Please complete the session


survey in the mobile app

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

You might also like