これはなに
- Step Functions のステートマシンを AWS CDK で定義する方法をメモ
Lambda 関数の作成
$ cat functions/hello.ts
const handler = async function (_: any) {
return {
result: 'Hello',
};
};
export { handler };
リソースの定義
$ cat lib/ts-lambda-stepfunctions.ts
import * as lambda from "@aws-cdk/aws-lambda";
import * as logs from "@aws-cdk/aws-logs";
import * as sfn from '@aws-cdk/aws-stepfunctions';
import * as tasks from '@aws-cdk/aws-stepfunctions-tasks';
import * as cdk from "@aws-cdk/core";
export class TsLambdaStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const helloFunction = new lambda.Function(this, "HelloFunction", {
runtime: lambda.Runtime.NODEJS_10_X,
code: lambda.Code.fromAsset("functions"),
handler: "hello.handler",
});
const _ = new logs.LogGroup(this, "HelloFunctionLogGroup", {
logGroupName: "/aws/lambda/" + helloFunction.functionName,
retention: logs.RetentionDays.ONE_DAY,
});
const definition = new tasks.LambdaInvoke(this, 'Get Hello', {
lambdaFunction: helloFunction,
payloadResponseOnly: true,
});
const machine = new sfn.StateMachine(this, "HelloStateMachine", {
definition,
timeout: cdk.Duration.minutes(1),
});
}
}
デプロイ
$ yarn build
$ cdk deploy
Pinned Articles
About
ウェブ界隈でエンジニアとして労働活動に励んでいる @gomi_ningen 個人のブログです
Tags
JavaScript
PowerShell
kibana
elasticsearch
fluentd
nginx
イベント
五十嵐裕美
村川梨衣
logrotate
IoT
Scala
Java
C言語
iputils
ICMP
WUG
mastodon
Swift
AWS
Clock
Windows
アーキテクチャ
PoEAA
iOS
DeviceFarm
プログラミング言語
OS
StepFunctions
Lambda
Serverless
terraform
ポエム
RHEL
ネットワーク
GraphQL
CloudWatch
Linux
Coreutils
network
nc
telnet
LinuxKernel
fpinscala
ELB
IAM
AppSync
EFS
Gradle
english