![Page 1: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/1.jpg)
Programming the Cloud with TypeScriptLuke Hoban
QCON LondonMarch 6th, 2019
![Page 2: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/2.jpg)
Why am I interested in this topic?
![Page 3: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/3.jpg)
Evolution of JavaScript
Browsers
DOM APIs
SPA Frameworks
Node.js
OS APIs
HTTP App/API Frameworks
??
AWS/Azure/etc APIs
Cloud App Frameworks
![Page 4: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/4.jpg)
Infrastructure as Code
![Page 5: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/5.jpg)
Infrastructure as Code Text
![Page 6: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/6.jpg)
Infrastructure as Software
![Page 7: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/7.jpg)
An Analogy
What’s missing?
● Variables● Loops● Functions● Abstraction● C Standard Library● Types
![Page 8: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/8.jpg)
Infrastructure as CodeAWSTemplateFormatVersion: '2010-09-09'Description: Slack BotParameters: BotName: Type: String SlackToken: Type: String WitAIToken: Type: StringOutputs: Url: Value: !Sub https://${api}.execute-api.${AWS::Region}.amazonaws.com/${stage}Resources: lambdaRole: Type: "AWS::IAM::Role" Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Principal: Service: lambda.amazonaws.com Action: "sts:AssumeRole" Path: / ManagedPolicyArns: - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" Policies: - PolicyName: lambda PolicyDocument: Version: '2012-10-17' Statement:
Effect: Allow Action: - 'lambda:ListFunctions' - 'lambda:InvokeFunction' Resource: '*'
botLambda: Type: "AWS::Lambda::Function" Properties: FunctionName: !Ref BotName Handler: index.handler Runtime: nodejs4.3 Role: !GetAtt [ lambdaRole, Arn ] Timeout: 300 Environment: Variables: SLACKTOKEN: !Ref SlackToken WITAITOKEN: !Ref WitAIToken Code: ZipFile: | 'use strict';
const AWS = require('aws-sdk'); const https = require('https'); const url = require('url'); const qs = require('querystring');
const AWS_REGION = process.env.AWS_REGION; const AWS_LAMBDA_FUNCTION_NAME = process.env.AWS_LAMBDA_FUNCTION_NAME; const slackToken = process.env.SLACKTOKEN; const witaiToken = process.env.WITAITOKEN;
const lambda = new AWS.Lambda();
exports.handler = (event, context, callback) => { const account_id = context.invokedFunctionArn.split(":")[4]; return processEvent(event, account_id) .then(res => callback(null, formatResponse("200", JSON.stringify({response_type: "in_channel", text: res })))) .catch(err => callback(null, formatResponse("400", err.message || err))) ; };
function processEvent(event, account_id) { // Code for bot command goes here
helpLambda: Type: "AWS::Lambda::Function" Properties: FunctionName: !Sub ${BotName}-help Handler: index.handler Runtime: nodejs4.3 Role: !GetAtt [ lambdaRole, Arn ] Timeout: 300 Code: ZipFile: | // Code for bot help goes here
botLambdaPermission: Type: "AWS::Lambda::Permission"
Properties: Action: "lambda:InvokeFunction" FunctionName: !GetAtt [ botLambda, Arn ] Principal: "apigateway.amazonaws.com" SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${api}/*"
helpLambdaPermission: Type: "AWS::Lambda::Permission"arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations - lambdaArn: !GetAtt helpLambda.Arn SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${api}/*" DependsOn: helpLambdaPermission
api: Type: "AWS::ApiGateway::RestApi" Properties: Name: !Ref BotName
anyMethod: Type: "AWS::ApiGateway::Method" Properties: AuthorizationType: NONE HttpMethod: ANY RestApiId: !Ref api ResourceId: !GetAtt api.RootResourceId MethodResponses:
- StatusCode: 200 Integration: Type: AWS_PROXY IntegrationHttpMethod: POST PassthroughBehavior: WHEN_NO_TEMPLATES Uri: !Sub - arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations - lambdaArn: !GetAtt botLambda.Arn DependsOn: botLambdaPermission
deployment: Type: "AWS::ApiGateway::Deployment" Properties: RestApiId: !Ref api StageName: DummyStage DependsOn: anyMethod
stage: Type: "AWS::ApiGateway::Stage" Properties: RestApiId: !Ref api StageName: bot DeploymentId: !Ref deployment
![Page 9: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/9.jpg)
DemoInfrastructure as Software
![Page 10: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/10.jpg)
Other Similar Approaches
![Page 11: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/11.jpg)
Process Models
11
Page
Transient
Script tags
Stateless
Process
Finite lifetime
ELF binaries
Largely stateless
Stack
Lives “forever”
Desired State
Fundamentally Stateful
![Page 12: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/12.jpg)
Cloud Native
EKS
Implications of Managed Services
Pre-Cloud
Lambda
S3 API Gateway
Aurora
MySQL
DataDog
Docker
PM2
DataDog CloudWatch
![Page 13: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/13.jpg)
DemoBreaking Down Barriers Between App and Infrastructure
![Page 14: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/14.jpg)
Programming at the level of Architecture Diagrams
![Page 15: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/15.jpg)
DemoProgramming at the level of Architecture Diagrams
![Page 16: with TypeScript Programming the Cloud - QCon London 2020 · Programming the Cloud Continue the march of JavaScript from Browser to Server to Cloud Apply Software Engineering to Cloud](https://reader035.vdocuments.net/reader035/viewer/2022070721/5ee14a1fad6a402d666c3940/html5/thumbnails/16.jpg)
Programming the Cloud
Continue the march of JavaScript from Browser to Server to Cloud
Apply Software Engineering to Cloud Infrastructure
Work at the right level of abstraction - raw infra or “architecture diagram”
Bridge the gap between App and Infra
A different kind of application model - “stacks” instead of processes