これはなに
- 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
GenAI
JavaScript
PowerShell
fluentd
kibana
elasticsearch
nginx
五十嵐裕美
村川梨衣
イベント
logrotate
IoT
Java
Scala
ICMP
iputils
C言語
WUG
mastodon
AWS
Swift
Clock
Windows
PoEAA
アーキテクチャ
iOS
DeviceFarm
プログラミング言語
OS
StepFunctions
Lambda
Serverless
terraform
ポエム
RHEL
ネットワーク
GraphQL
CloudWatch
Linux
Coreutils
nc
telnet
network
LinuxKernel
fpinscala
ELB
IAM
AppSync
EFS
Gradle