More Related Content
Similar to 20200803 - Serverless with AWS @ HELTECH (20)
More from Marcia Villalba (14)
20200803 - Serverless with AWS @ HELTECH
- 1. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Marcia Villalba
Developer Advocate AWS
@mavi888uy
Serverless with AWS
- 2. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
About me – Marcia Villalba
AWS Developer Advocate
Doing serverless since 2016
Host of FooBar YouTube Channel
https://youtube.com/foobar_codes
@mavi888uy
- 3. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Levelofabstraction
Focus on business logic
Physical machines Requires “guess” planning
Lives for years on-premises
Heavy investments (CAPEX)
Low innovation factor
Deploy in months
Computing evolution: A paradigm shift
- 4. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Levelofabstraction
Focus on business logic
Virtual machines
Hardware independence
Faster provisioning speed (minutes/hours)
Trade CAPEX for OPEX
More scale
Elastic resources
Faster speed and agility
Reduced maintenance
Computing evolution: A paradigm shift
- 5. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Levelofabstraction
Focus on business logic
Containerization
Platform independence
Consistent runtime environment
Higher resource utilization
Easier and faster deployments
Isolation and sandboxing
Start speed (deploy in seconds)
Computing evolution: A paradigm shift
- 6. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Lambda
Levelofabstraction
Focus on business logic
Continuous scaling
Fault tolerance built in
Event-driven
Pay for value
Zero maintenance
Serverless
Computing evolution: A paradigm shift
- 7. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What it means that something is serverless?
No managing infrastructure High availability built in
Pay for what you useScales automagically
- 8. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
- 9. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Function as a Service (FaaS)
“AWS Lambda lets you run code without
provisioning or managing servers. ...
…Just upload your code and Lambda takes care
of everything required to run and scale your code
with high availability.
You can set up your code to automatically
trigger from other AWS services or call it directly
from any web or mobile app”
AWS – Lambda definition
AWS
Lambda
- 10. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
How AWS Lambda works?
Event source Function Services
Node.js
Python
Java
C#
Go
Custom runtimes
Changes in
data state
Requests to
endpoints
Changes in
resource state
Amazon S3
DynamoDB
Amazon
SQS
- 11. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Managed services
Amazon S3
Amazon SQS
DynamoDB
- 12. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
- 13. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.@theburningmonk
- 14. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Why to use serverless?
- 15. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless is a change of mindset
”Serverless is a
methodology for
planning, building and
deploying software in a
way that maximizes value
by minimizing
undifferentiated heavy
lifting…”
Jeremy Daly
- 16. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Benefits of using serverless
• Focusing on what is important to your business
• Faster time to market
• Reduce initial investment
• Automagical scalability
• Modular and decouple architecture
- 17. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Common serverless use cases
Web
applications
• Static
websites
• Complex web
apps
• Packages for
Flask and
Express
Data
processing
• Real-time
• MapReduce
• Batch
Chatbots
• Powering
chatbot logic
Backends
• Apps and
services
• Mobile
• IoT
</></>
Amazon
Alexa
• Powering
voice-enabled
apps
• Alexa Skills Kit
IT
automation
• Policy engines
• Extending
AWS services
• Infrastructure
management
- 18. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Let’s build something
- 19. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
The simplest serverless example
Amazon API Gateway
Was greeted?
Amazon DynamoDB
Client
Save a greeting
/hello
POST /hello
GET /hello
- 20. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Define the infrastructure
SaveHelloFunction:
Type: 'AWS::Serverless::Function’
Properties:
Handler: handler.saveHello
Runtime: nodejs12.x
CodeUri: ./hello
Policies:
- DynamoDBCrudPolicy:
TableName: ExampleTable
Events:
HelloAPI:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /hello
Method: POST
1 Lambda function
- 21. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Define the infrastructure
SaveHelloFunction:
Type: 'AWS::Serverless::Function’
Properties:
Handler: handler.saveHello
Runtime: nodejs12.x
CodeUri: ./hello
Policies:
- DynamoDBCrudPolicy:
TableName: ExampleTable
Events:
HelloAPI:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /hello
Method: POST
Function configuration
- 22. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Define the infrastructure
SaveHelloFunction:
Type: 'AWS::Serverless::Function’
Properties:
Handler: handler.saveHello
Runtime: nodejs12.x
CodeUri: ./hello
Policies:
- DynamoDBCrudPolicy:
TableName: ExampleTable
Events:
HelloAPI:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /hello
Method: POST
Function permissions
- 23. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Define the infrastructure
SaveHelloFunction:
Type: 'AWS::Serverless::Function’
Properties:
Handler: handler.saveHello
Runtime: nodejs12.x
CodeUri: ./hello
Policies:
- DynamoDBCrudPolicy:
TableName: ExampleTable
Events:
HelloAPI:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /hello
Method: POST
Function trigger
- 24. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Define the infrastructure
API Gateway definition
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: dev
Cors:
AllowMethods: "'*’”
AllowHeaders: "'*’”
AllowOrigin: "'*'"
- 25. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Define the infrastructure
ExampleTable:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
- AttributeName: "name"
AttributeType: "S"
KeySchema:
- AttributeName: "name"
KeyType: "HASH"
BillingMode: 'PAY_PER_REQUEST’
TableName: 'ExampleTable'
DynamoDB table
definition
- 26. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Write the code
…
exports.saveHello = async (event) => {
const name = event.queryStringParameters.name;
const item = {
name: name,
date: Date.now()
}
const savedItem = await saveItem(item);
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*’
},
body: JSON.stringify(savedItem),
}
}
…
In the handler.js
Code that the
function will execute
- 27. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Deploy the project to the cloud
$ sam deploy --guided
- 28. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Test in postman
- 29. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Add the backend to a website
…
const wasGreeted = async () => {
const response = await fetch(
`${awsConfig.endpoint}hello?name=${name}`, {
mode: 'cors’
});
const responseData = await response.text();
setShowResult(true);
setApiMessage(responseData);
};
…
- 30. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Add the backend to a website
…
const wasGreeted = async () => {
const response = await fetch(
`${awsConfig.endpoint}hello?name=${name}`, {
mode: 'cors’
});
const responseData = await response.text();
setShowResult(true);
setApiMessage(responseData);
};
…
const awsconfig = {
"aws_project_region": "<REGION>",
"api_gateway_api_name": "<name of API>",
"endpoint": "<endpoint-URL>"
};
export default awsconfig;
- 31. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Testing it out
- 32. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Get the code
https://github.com/mavi888/first-serverless-app
- 33. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Thank you!
Marcia Villalba
@mavi888uy
Youtube channel: http://bit.ly/foobar-youtube