Slide 1

Slide 1 text

Infrastructure as TypeScript

Slide 2

Slide 2 text

• Software developer • Cloud • Serverless • Functional Programming, F# • Microsoft Azure MVP https://mikhail.io @MikhailShilkov About me

Slide 3

Slide 3 text

Sample App

Slide 4

Slide 4 text

URL Shortener

Slide 5

Slide 5 text

Serverless URL Shortener AWS DynamoDB Table “URLs” AWS Lambda “Add URL” AWS Lambda “Open URL”

Slide 6

Slide 6 text

AWS Lambda code const aws = require('aws-sdk'); const table = new aws.DynamoDB.DocumentClient(); exports.handler = async (event) => { const name = event.path.substring(1); const params = { TableName: "urls", Key: { "name": name } }; const value = await table.get(params).promise(); const url = value && value.Item && value.Item.url; return url ? { statusCode: 301, body: "", headers: { "Location": url } } : { statusCode: 404, body: name + " not found" }; };

Slide 7

Slide 7 text

AWS Lambda code const aws = require('aws-sdk'); const table = new aws.DynamoDB.DocumentClient(); exports.handler = async (event) => { const name = event.path.substring(1); const params = { TableName: "urls", Key: { "name": name } }; const value = await table.get(params).promise(); const url = value && value.Item && value.Item.url; return url ? { statusCode: 301, body: "", headers: { "Location": url } } : { statusCode: 404, body: name + " not found" }; };

Slide 8

Slide 8 text

AWS Lambda code const aws = require('aws-sdk'); const table = new aws.DynamoDB.DocumentClient(); exports.handler = async (event) => { const name = event.path.substring(1); const params = { TableName: "urls", Key: { "name": name } }; const value = await table.get(params).promise(); const url = value && value.Item && value.Item.url; return url ? { statusCode: 301, body: "", headers: { "Location": url } } : { statusCode: 404, body: name + " not found" }; };

Slide 9

Slide 9 text

Diagram of the app with all resources Lambda “Add URL” Lambda “Open URL” DynamoDB “URLs” API Gateway S3 Bucket Static site

Slide 10

Slide 10 text

Diagram of the app with all resources Lambda “Add URL” Lambda “Open URL” DynamoDB “URLs” API Gateway S3 Bucket Static site Stage Deployment REST endpoint Permissions Permissions Policy Bucket Objects

Slide 11

Slide 11 text

Options to deploy the infra …

Slide 12

Slide 12 text

Options: AWS Web Console

Slide 13

Slide 13 text

Options: AWS CLI

Slide 14

Slide 14 text

Options: CloudFormation Resources: S3BucketForURLs: Type: "AWS::S3::Bucket" DeletionPolicy: Delete Properties: BucketName: !If [ "CreateNewBucket", "AWS … WebsiteConfiguration: IndexDocument: "index.html" LifecycleConfiguration: Rules: - Id: DisposeShortUrls ExpirationInDays: !Ref URLExpiration Prefix: "u" Status: Enabled

Slide 15

Slide 15 text

Options: Terraform resource "aws_lambda_function" "apply_security_headers" { provider = "aws.cloudfront_acm" filename = "lambda_functions/security_headers.zip" function_name = "apply_security_headers" role = "${aws_iam_role.short_url_lambda_iam.arn}" handler = "lambda_function.handler" source_code_hash = "${data.archive.security.base64}" runtime = "nodejs8.10" publish = true tags = { Project = "short_urls" } }

Slide 16

Slide 16 text

Options: Serverless Framework functions: store: handler: api/store.handle events: - http: path: / method: post cors: true resources: Resources: ServerlesslyRedirectS3Bucket: Type: AWS::S3::Bucket Properties: BucketName: ${file(config.json):BUCKET} AccessControl: PublicRead WebsiteConfiguration:

Slide 17

Slide 17 text

Desired properties of infra

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Pulumi

Slide 21

Slide 21 text

Pulumi CLI Stacks State Demo

Slide 22

Slide 22 text

How Pulumi works CLI and Engine Last deployed state index.ts Language host AWS Azure GCP Kubernetes new Resource() Create, update, delete

Slide 23

Slide 23 text

Types IntelliSense Compiler errors Language Constructs Reusable Components Component Library Blend of Infra and Code Pulumi Cloud Demo

Slide 24

Slide 24 text

Pulumi Layers Cloud API Resource Provider Pulumi Resources Pulumi AWS Cloud Pulumi Cloud

Slide 25

Slide 25 text

Conclusions

Slide 26

Slide 26 text

USE INFRASTRUCTURE- AS-CODE Making Cloud Apps?

Slide 27

Slide 27 text

Real Programming Language! What Kind of “Code” ?

Slide 28

Slide 28 text

Slides and demos: https://github.com/MikhailShilkov/fosdem2019 Pulumi: https://pulumi.io/ Usage examples: https://github.com/pulumi/examples Useful Links

Slide 29

Slide 29 text

No content