build a modern api with aws - becksteadn.github.io a modern api with aws.pdf · lambda deployment...

38
Build a Modern API with AWS Nathaniel Beckstead

Upload: others

Post on 06-Jun-2020

46 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Build a Modern API with AWS

Nathaniel Beckstead

Page 2: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

2

API Gateway Lambda

S3

Dynamo DB

scriptingis.life/glimpseid

Page 3: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

$whoamiNathaniel Beckstead▫ C L O U D▫ D E V O P S▫ C Y B E R

scriptingis.life

3

Page 4: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Background▫ Interned in KeyBank SOC▫ Automated parts of phishing response▫ URLScan.io

- Screenshot- HTTP Requests- IPs/ASNs contacted

4

Page 5: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Background

5

Page 6: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

6

Page 7: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

7

Page 8: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

HTTP Info

8

▫ Runs in a Docker container▫ Selenium

- Drive the browser- Screenshot

▫ Browsermob Proxy- Record HTTP requests and responses- Export to CSV

Page 9: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

HTTP Info

9

Page 10: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Selenium▫ Web browser automation primarily designed for

testing▫ Render a page and interact

with elements

10

Page 11: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

11

API Gateway Lambda

S3

Dynamo DB

Page 12: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

LambdaServerless Computing

Page 13: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Lambda▫ Serverless Computing▫ Only charged for execution time and resources used▫ Run when triggered by

- AWS IoT- DynamoDB, S3- API Gateway- Time

13

Page 14: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Limitations▫ Need to include all resources in upload

- ZIP - 50MB- S3 - 250MB

▫ Small compute power- 128MB - 3GB memory- CPU power scales with memory limit

▫ No root access- Limited OS privileges

14

Page 15: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Lambda Cost▫ 1,000,000 requests free▫ 400,000 GB-seconds of compute resources free

▫ 800,000 seconds of runtime with 512MB memory- ~40,000 20-second scans

15

Page 16: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Lambda▫ Python script with Selenium driving Chromium

1. Load webpage2. Screenshot3. Upload image to S3

16

21Buttons/pychromeless

Page 17: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Lambda▫ Python script with Selenium driving Chromium

17

21Buttons/pychromeless

Page 18: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

18

Page 19: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Lambda▫ Lambda invokes a function in your code▫ Parameters passed as a dictionary

19

Page 20: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Lambda Deployment▫ Makefile▫ AWS CLI

20

Page 21: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

StorageSimple Storage Service (S3) and DynamoDB

Page 22: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

S3▫ Key-Value Storage▫ Host publicly accessible images▫ Uploading done through boto Python module

22

Page 23: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

S3 Cost▫ Storage

- First 50TB - $0.023 per GB▫ Access

- PUT- Data added $0.002 per GB - $0.005 per 1,000 requests

- GET- Data returned $0.0007 per GB- $0.0004 per 1,000 requests

23

Page 24: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

DynamoDB▫ NoSQL Database

- No set structure = No normalizing!▫ No setup, maintenance, or clustering

▫ Cost- $0.25 per GB of storage- $1.25 per million writes- $0.25 per million reads- Free Tier - 25GB storage, 2.5 million reads, 1GB data transfer

out

24

Page 25: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

API GatewayREST API Development and Management

Page 26: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

API Gateway

26

▫ Visual API development▫ Proxy for other AWS services

- DynamoDB queries▫ Convert between HTTP requests and Lambda

execution

Page 27: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

API Gateway

27

Page 28: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

API Gateway Cost▫ $3.50 per million API calls▫ Caching

- 0.5GB for $0.020 per hour- $15 per month

28

Page 29: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

WebsiteFrontend is hard :(

Page 30: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Github Pages▫ Host a static site for free

1. Make a new repository2. Add an index.html3. Settings -> GitHub Pages -> master branch4. Struggle with CSS5. Profit

30

Page 31: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Conclusions

Page 32: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Why Use The Cloud?▫ Easy

- Heavy lifting done by AWS- Graphical interfaces for everything- Logging and dashboards built in

▫ Cheap- Free tiers- Charge by the millions

▫ Scalable- Duplicate and automate

32

Page 33: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Easy

33

Page 34: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Dashboards

34

Page 35: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Cheap

35

Page 36: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Next Up▫ Continuous Integration▫ Network Activity Logging▫ Support Multiple Regions, User-Agents▫ ...

36

Page 37: Build a Modern API with AWS - Becksteadn.Github.Io a Modern API with AWS.pdf · Lambda Deployment Makefile AWS CLI 20. Storage Simple Storage Service (S3) and DynamoDB. S3 ... Continuous

Questions?scriptingis.life/glimpseid

37