Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TypeScriptだけでAWSを開発する

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for ufoo68 ufoo68
April 14, 2020

 TypeScriptだけでAWSを開発する

Avatar for ufoo68

ufoo68

April 14, 2020
Tweet

More Decks by ufoo68

Other Decks in Programming

Transcript

  1. 自己紹介 • 名前 ◦ ufoo68 • やってること ◦ AWSを使った開発 ◦

    スポーツIoTLTの主催 • 最近とった資格 ◦ ソリューションアーキテクトアソシエイト ◦ Alexaスキルビルダー
  2. CloudFormationを使う "myDynamoDBTable" : { "Type" : "AWS::DynamoDB::Table", "Properties" : {

    "AttributeDefinitions": [ { "AttributeName" : {"Ref" : "HashKeyElementName"}, "AttributeType" : {"Ref" : "HashKeyElementType"} } ], "KeySchema": [ { "AttributeName": {"Ref" : "HashKeyElementName"}, "KeyType": "HASH" } ], "ProvisionedThroughput" : { "ReadCapacityUnits" : {"Ref" : "ReadCapacityUnits"}, "WriteCapacityUnits" : {"Ref" : "WriteCapacityUnits"} } } } こんな感じで、json(or yaml)でAWSのインフラや設定を定義できる AWSサービス
  3. CDKのいいところ • 各リソースの型が定義してある ◦ 公式ドキュメントを見ずに構文が予測できる ◦ 構文エラーをデプロイする前に検出することができる • 使い慣れた文法で書ける ◦

    メジャーな言語が揃っている • 共通化ができる ◦ constructという機能でライブラリ化ができる ◦ 実装ミスを防ぐ ◦ クソ長い行数のCloudFormationに苦しむことがない
  4. 型を定義しながらAWSが開発できる export interface LambdaApiProps { environment?: { [key: string]: string

    } lambdaPath: string } export class LambdaApi extends cdk.Construct { public readonly handler: lambda.Function public readonly api: apigateway.LambdaRestApi constructor(scope: cdk.Construct, id: string, { environment, lambdaPath }: LambdaApiProps) { super(scope, id) this.handler = new lambda.Function(this, `${id}Handler`, { runtime: lambda.Runtime.NODEJS_12_X, code: lambda.Code.asset(lambdaPath), handler: 'index.handler', environment }) this.api = new apigateway.LambdaRestApi(this, `${id}Endpoint`, { handler: this.handler }) } }