MBC CQRS サーバーレス フレームワーク TO-DO システム作成 1 ー 環境構築
Technology
Aug 30, 2024
MBC CQRS サーバーレス フレームワークを使用してTODOシステムを作成してみましょう。
まずは、MBC CQRS サーバーレス フレームワークで開発するための環境を用意しましょう。
環境作成
MBC CQRS サーバーレス フレームワークを使ってシステムを構築する際の環境を作成しましょう。
前提条件
以下のモジュールをインストールしているものとします。
- Node.jS
- JQ cli
- AWS cli
- Docker
また、macOSを使用してオペレーションを記載します。WindowsやLinuxで操作する際は読み替えて操作をして下さい。
mbc-cqrs-serverless cli をインストール
次のコマンドを実行し mbc-cqrs-serverless cli をインストールします。
npm i -g @mbc-cqrs-serverless/cli
すでに上記コマンドをインストールしている場合は更新版があるかどうかチェックするため、以下のコマンドを実行します。
npm update -g @mbc-cqrs-serverless/cli
プロジェクト作成
次のコマンドを実行しプロジェクトを作成します。
mbc new mbc-todo-sample
上記を実行すると次のような表示になります。
Executing command 'new' for application 'mbc-todo-sample' with options '{}'
Generating MBC cqrs serverless application in /Users/koichi.murakami/code/blog/mbc-todo-sample
Initialized empty Git repository in /Users/koichi.murakami/code/blog/mbc-todo-sample/.git/
Installing packages in /Users/koichi.murakami/code/blog/mbc-todo-sample
npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm WARN deprecated topo@2.1.1: This module has moved and is now available at @hapi/topo. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated items@2.2.1: This module has been deprecated. It's not used by modern hapi versions anymore. Please refer to https://hapi.dev for migration to latest versions.
npm WARN deprecated vise@2.1.1: This module has moved and is now available at @hapi/vise. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated nigel@2.1.1: This module has moved and is now available at @hapi/nigel. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated pez@2.2.2: This module has moved and is now available at @hapi/pez. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated bourne@1.3.3: This module has moved and is now available at @hapi/bourne. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated content@3.1.2: This module has moved and is now available at @hapi/content. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated mimos@3.1.1: This module has moved and is now available at @hapi/mimos. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated iron@4.1.1: This module has moved and is now available at @hapi/iron. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated catbox-memory@2.1.1: This module has moved and is now available at @hapi/catbox-memory. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated ammo@2.1.2: This module has moved and is now available at @hapi/ammo. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated heavy@4.1.1: This module has moved and is now available at @hapi/heavy. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated cryptiles@4.1.3: This module has moved and is now available at @hapi/cryptiles. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated cryptiles@3.2.1: This module has moved and is now available at @hapi/cryptiles. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated cryptiles@3.2.1: This module has moved and is now available at @hapi/cryptiles. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated cryptiles@3.2.1: This module has moved and is now available at @hapi/cryptiles. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@5.3.3: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated podium@1.4.1: This module has moved and is now available at @hapi/podium. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated b64@3.1.1: This module has moved and is now available at @hapi/b64. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated subtext@5.1.3: This module has moved and is now available at @hapi/subtext. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated statehood@5.1.1: This module has moved and is now available at @hapi/statehood. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated shot@3.5.2: This module has moved and is now available at @hapi/shot. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated boom@7.3.0: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated @koa/router@9.4.0: **IMPORTANT 10x+ PERFORMANCE UPGRADE**: Please upgrade to v12.0.1+ as we have fixed an issue with debuglog causing 10x slower router benchmark performance, see https://github.com/koajs/router/pull/173
npm WARN deprecated catbox@7.2.1: This module has moved and is now available at @hapi/catbox. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated call@4.1.2: This module has moved and is now available at @hapi/call. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated hoek@6.1.3: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated wreck@12.6.2: This module has moved and is now available at @hapi/wreck. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated hoek@4.3.1: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated accept@2.2.3: This module has moved and is now available at @hapi/accept. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated somever@1.1.1: This module has moved and is now available at @hapi/somever. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
npm WARN deprecated @aws-sdk/signature-v4@3.374.0: This package has moved to @smithy/signature-v4
npm WARN deprecated @hapi/address@1.0.1: Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated h2o2@6.1.0: This module has moved and is now available at @hapi/h2o2. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated uuid@3.3.2: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated hapi@16.8.4: This version contains severe security issues and defects and should not be used! Please upgrade to the latest version of @hapi/hapi
npm WARN deprecated superagent@8.1.2: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net
npm WARN deprecated superagent@7.1.6: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net
npm WARN deprecated joi@10.6.0: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated joi@12.1.1: Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated joi@12.1.1: Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated joi@12.1.1: Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated joi@12.1.1: Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated joi@12.1.1: Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
npm WARN deprecated joi@12.1.1: Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.
> mbc-todo-sample@0.0.1 postinstall
> prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
✔ Generated Prisma Client (v5.19.1) to ./node_modules/@prisma/client in 96ms
Start by importing your Prisma Client (See: http://pris.ly/d/importing-client)
Tip: Want to react to database changes in your app as they happen? Discover how with Pulse: https://pris.ly/tip-1-pulse
added 1675 packages, and audited 1676 packages in 2m
228 packages are looking for funding
run `npm fund` for details
40 vulnerabilities (7 moderate, 29 high, 4 critical)
To address issues that do not require attention, run:
npm audit fix
To address all issues possible (including breaking changes), run:
npm audit fix --force
Some issues need review, and may require choosing
a different dependency.
Run `npm audit` for details.
開発環境の設定
プロジェクトのディレクトリに移動し環境設定ファイルをコピーします。
cd mbc-todo-sample ← mbc new で設定したプロジェクト名
cp .env.local .env
開発モードでビルドする
次のコマンドで実行し開発モードでビルドします。
npm run build
開発用環境の立ち上げ
別のターミナルでプロジェクトのディレクトリを開き次のコマンドを実行します。
npm run offline:docker
Dockerコンテナが起動されると次のような表示されます。
> mbc-todo-sample@0.0.1 offline:docker
> cd infra-local && mkdir -p docker-data/.cognito && cp -r cognito-local/db docker-data/.cognito && docker compose up --remove-orphans
WARN[0000] /Users/koichi.murakami/code/blog/mbc-todo-sample/infra-local/docker-compose.yml: `version` is obsolete
[+] Running 9/8
✔ Container esc-api Removed 0.0s
✔ Container infra-local-appsync-1 Created 0.0s
✔ Container infra-local-stepfunctions-local-1 Created 0.0s
✔ Container infra-local-cognito-local-1 Recreated 0.1s
✔ Container infra-local-rds-1 Recreated 0.1s
✔ Container infra-local-localstack-1 Recreated 0.1s
✔ Container infra-local-queue-1 Recreated 0.1s
✔ Container infra-local-dynamodb-local-1 Recreated 0.1s
✔ Container infra-local-dynamodb-admin-1 Recreated 0.0s
Attaching to appsync-1, cognito-local-1, dynamodb-admin-1, dynamodb-local-1, localstack-1, queue-1, rds-1, stepfunctions-local-1
rds-1 | 2024-09-17 01:31:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.4.0-1.el9 started.
queue-1 | 01:31:50.995 [main] INFO org.elasticmq.server.Main$ - Starting ElasticMQ server (1.6.3) ...
queue-1 | 01:31:51.040 [elasticmq-pekko.actor.default-dispatcher-8] INFO o.a.pekko.event.slf4j.Slf4jLogger - Slf4jLogger started
rds-1 | 2024-09-17 01:31:51+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
rds-1 | 2024-09-17 01:31:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.4.0-1.el9 started.
queue-1 | 01:31:51.082 [elasticmq-pekko.actor.default-dispatcher-9] INFO o.e.rest.sqs.TheSQSRestServerBuilder - Started SQS rest server, bind address 0.0.0.0:9324, visible server address * (depends on incoming request path)
queue-1 | 01:31:51.084 [main] INFO o.e.rest.sqs.TheSQSRestServerBuilder - Metrics MBean org.elasticmq:name=Queues successfully registered
queue-1 | 01:31:51.086 [elasticmq-pekko.actor.default-dispatcher-9] INFO o.e.r.s.TheStatisticsRestServerBuilder - Started statistics rest server, bind address 0.0.0.0:9325
queue-1 | 01:31:51.086 [main] INFO org.elasticmq.server.Main$ - === ElasticMQ server (1.6.3) started in 149 ms ===
queue-1 | 01:31:51.086 [elasticmq-pekko.actor.default-dispatcher-8] INFO o.elasticmq.actor.QueueManagerActor - Creating queue CreateQueueData(notification-queue,Some(MillisVisibilityTimeout(60000)),Some(PT5S),Some(PT0S),Some(2024-09-17T01:31:51.017Z),Some(2024-09-17T01:31:51.017Z),None,false,false,None,None,Map())
queue-1 | 01:31:51.086 [elasticmq-pekko.actor.default-dispatcher-8] INFO o.elasticmq.actor.QueueManagerActor - Creating queue CreateQueueData(task-action-queue,Some(MillisVisibilityTimeout(60000)),Some(PT5S),Some(PT0S),Some(2024-09-17T01:31:51.017Z),Some(2024-09-17T01:31:51.017Z),None,false,false,None,None,Map())
appsync-1 |
appsync-1 | > appsync-simulator-starter-kit@1.0.0 serve
appsync-1 | > ts-node src/main.ts
appsync-1 |
rds-1 | 2024-09-17 01:31:51+00:00 [Note] [Entrypoint]: Initializing database files
rds-1 | 2024-09-17T01:31:51.220362Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
rds-1 | 2024-09-17T01:31:51.221250Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.4.0) initializing of server in progress as process 81
rds-1 | 2024-09-17T01:31:51.225505Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
rds-1 | 2024-09-17T01:31:51.232624Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
cognito-local-1 |
cognito-local-1 | > cognito-local@1.0.0 dev
cognito-local-1 | > HOST=0.0.0.0 npx cognito-local
cognito-local-1 |
rds-1 | 2024-09-17T01:31:51.645868Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
localstack-1 |
localstack-1 | LocalStack version: 3.2.1.dev
localstack-1 | LocalStack build date: 2024-03-25
localstack-1 | LocalStack build git hash: bb20f36c0
localstack-1 |
dynamodb-admin-1 | database endpoint: dynamodb-local:8000
dynamodb-admin-1 | region: ap-northeast-1
dynamodb-admin-1 | accessKey: local
dynamodb-admin-1 |
dynamodb-admin-1 | dynamodb-admin listening on http://:::8001 (alternatively http://0.0.0.0:8001)
dynamodb-admin-1 | (node:1) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023.
dynamodb-admin-1 |
dynamodb-admin-1 | Please migrate your code to use AWS SDK for JavaScript (v3).
dynamodb-admin-1 | For more information, check the migration guide at https://a.co/7PzMCcy
dynamodb-admin-1 | (Use `node --trace-warnings ...` to show where the warning was created)
dynamodb-local-1 | Initializing DynamoDB Local with the following configuration:
dynamodb-local-1 | Port: 8000
dynamodb-local-1 | InMemory: false
dynamodb-local-1 | Version: 2.5.1
dynamodb-local-1 | DbPath: ./data
dynamodb-local-1 | SharedDb: true
dynamodb-local-1 | shouldDelayTransientStatuses: false
dynamodb-local-1 | CorsParams: null
dynamodb-local-1 |
stepfunctions-local-1 | Step Functions Local
stepfunctions-local-1 | Version: 2.0.0
stepfunctions-local-1 | Build: 2024-05-18
stepfunctions-local-1 | 2024-09-17 01:31:51.931: Configure [AWS_ACCOUNT_ID] to [101010101010]
stepfunctions-local-1 | 2024-09-17 01:31:51.931: Configure [AWS_DEFAULT_REGION] to [ap-northeast-1]
stepfunctions-local-1 | 2024-09-17 01:31:51.931: Configure [LAMBDA_ENDPOINT] to [http://host.docker.internal:3002]
stepfunctions-local-1 | 2024-09-17 01:31:51.931: Configure [DYNAMODB_ENDPOINT] to [http://host.docker.internal:8000]
stepfunctions-local-1 | 2024-09-17 01:31:51.932: Configure [ECS_ENDPOINT] to [VALUE]
stepfunctions-local-1 | 2024-09-17 01:31:51.932: Configure [SQS_ENDPOINT] to [http://host.docker.internal:9324]
stepfunctions-local-1 | 2024-09-17 01:31:51.932: Configure [SNS_ENDPOINT] to [http://host.docker.internal:4002]
stepfunctions-local-1 | 2024-09-17 01:31:51.932: Configure [STEP_FUNCTIONS_ENDPOINT] to [http://host.docker.internal:8083]
stepfunctions-local-1 | 2024-09-17 01:31:51.943: Failed to load credentials from environment because Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY))
stepfunctions-local-1 | 2024-09-17 01:31:52.041: Failed to load credentials from profile: default because profile file cannot be null
stepfunctions-local-1 | 2024-09-17 01:31:52.041: Failed to load credentials from system properties because Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey)
stepfunctions-local-1 | 2024-09-17 01:31:52.041: Failed to load credentials, default to dummy credentials, so any connection to AWS services will not work, connections to local endpoints are not affected.
stepfunctions-local-1 | 2024-09-17 01:31:52.297: Starting server on port 8083 with account 101010101010, region ap-northeast-1
cognito-local-1 | (node:29) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023.
cognito-local-1 |
cognito-local-1 | Please migrate your code to use AWS SDK for JavaScript (v3).
cognito-local-1 | For more information, check the migration guide at https://a.co/7PzMCcy
cognito-local-1 | (Use `node --trace-warnings ...` to show where the warning was created)
cognito-local-1 | [1726536712352] INFO: NONE NONE Cognito Local running on http://0.0.0.0:9229
stepfunctions-local-1 | SLF4J: No SLF4J providers were found.
stepfunctions-local-1 | SLF4J: Defaulting to no-operation (NOP) logger implementation
stepfunctions-local-1 | SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
rds-1 | 2024-09-17T01:31:52.904579Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
localstack-1 | 2024-09-17T01:31:53.068 INFO --- [-functhread4] hypercorn.error : Running on https://0.0.0.0:4566 (CTRL + C to quit)
localstack-1 | 2024-09-17T01:31:53.068 INFO --- [-functhread4] hypercorn.error : Running on https://0.0.0.0:4566 (CTRL + C to quit)
localstack-1 | Ready.
appsync-1 | 🚀 App Sync Simulator started at http://localhost:4001/graphql
appsync-1 | (node:18) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023.
appsync-1 |
appsync-1 | Please migrate your code to use AWS SDK for JavaScript (v3).
appsync-1 | For more information, check the migration guide at https://a.co/7PzMCcy
appsync-1 | (Use `node --trace-warnings ...` to show where the warning was created)
rds-1 | 2024-09-17T01:31:54.397543Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
rds-1 | 2024-09-17 01:31:54+00:00 [Note] [Entrypoint]: Database files initialized
rds-1 | 2024-09-17 01:31:54+00:00 [Note] [Entrypoint]: Starting temporary server
rds-1 | 2024-09-17T01:31:54.433984Z 0 [System] [MY-015015] [Server] MySQL Server - start.
rds-1 | 2024-09-17T01:31:54.583619Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.4.0) starting as process 126
rds-1 | 2024-09-17T01:31:54.586071Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
rds-1 | 2024-09-17T01:31:54.598334Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
rds-1 | 2024-09-17T01:31:54.736424Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
rds-1 | 2024-09-17T01:31:54.884014Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
rds-1 | 2024-09-17T01:31:54.884091Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
rds-1 | 2024-09-17T01:31:54.887221Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
rds-1 | 2024-09-17T01:31:54.894513Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.4.0' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
rds-1 | 2024-09-17 01:31:54+00:00 [Note] [Entrypoint]: Temporary server started.
rds-1 | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
rds-1 | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
rds-1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
rds-1 | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
rds-1 | 2024-09-17T01:31:55.151678Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
rds-1 | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
rds-1 | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
rds-1 | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
rds-1 | 2024-09-17 01:31:55+00:00 [Note] [Entrypoint]: Creating database cqrs
rds-1 |
rds-1 | 2024-09-17 01:31:55+00:00 [Note] [Entrypoint]: Stopping temporary server
rds-1 | 2024-09-17T01:31:55.658816Z 12 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.4.0).
rds-1 | 2024-09-17T01:31:56.476290Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.4.0) MySQL Community Server - GPL.
rds-1 | 2024-09-17T01:31:56.476315Z 0 [System] [MY-015016] [Server] MySQL Server - end.
rds-1 | 2024-09-17 01:31:56+00:00 [Note] [Entrypoint]: Temporary server stopped
rds-1 |
rds-1 | 2024-09-17 01:31:56+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
rds-1 |
rds-1 | 2024-09-17T01:31:56.698056Z 0 [System] [MY-015015] [Server] MySQL Server - start.
rds-1 | 2024-09-17T01:31:56.841444Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.4.0) starting as process 1
rds-1 | 2024-09-17T01:31:56.843613Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
rds-1 | 2024-09-17T01:31:56.850334Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
rds-1 | 2024-09-17T01:31:56.947789Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
rds-1 | 2024-09-17T01:31:57.073639Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
rds-1 | 2024-09-17T01:31:57.073704Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
rds-1 | 2024-09-17T01:31:57.076655Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
rds-1 | 2024-09-17T01:31:57.084042Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.4.0' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
rds-1 | 2024-09-17T01:31:57.350376Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
v View in Docker Desktop w Enable Watch
テーブルの作成
次のコマンドを実行しテーブル等を作成する
npm run migrate
上記を実行すると次のような表示になります。
> mbc-todo-sample@0.0.1 migrate
> npm run migrate:rds && npm run migrate:ddb
> mbc-todo-sample@0.0.1 migrate:rds
> prisma migrate deploy
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MySQL database "cqrs" at "localhost:3306"
No migration found in prisma/migrations
No pending migrations to apply.
> mbc-todo-sample@0.0.1 migrate:ddb
> ts-node prisma/ddb.ts
Clear table stream arn in .env
creating table: master-command
creating table: master-data
creating table: master-history
table exists: arn:aws:dynamodb:ddblocal:000000000000:table/local-demo-master-history => stream: undefined
table exists: arn:aws:dynamodb:ddblocal:000000000000:table/local-demo-master-command => stream: arn:aws:dynamodb:ddblocal:000000000000:table/local-demo-master-command/stream/2024-09-17T01:39:06.577
table exists: arn:aws:dynamodb:ddblocal:000000000000:table/local-demo-master-data => stream: undefined
creating table: sequences
creating table: tasks
table exists: arn:aws:dynamodb:ddblocal:000000000000:table/local-demo-tasks => stream: arn:aws:dynamodb:ddblocal:000000000000:table/local-demo-tasks/stream/2024-09-17T01:39:06.618
table exists: arn:aws:dynamodb:ddblocal:000000000000:table/local-demo-sequences => stream: undefined
No tables were created
ブラウザーで http://localhost:8001 を開くと次のような画面になります。
開発用サーバーの立ち上げ
別のターミナルでプロジェクトのディレクトリを開き次のコマンドを実行します。
npm run offline:sls
上記を実行すると次のような表示になります。
> mbc-todo-sample@0.0.1 offline:sls
> /bin/bash ./infra-local/scripts/trigger_ddb_stream.sh & ln -f .env $PWD/infra-local/.env && cd infra-local && NODE_ENV=development AWS_ACCESS_KEY_ID=DUMMYIDEXAMPLE AWS_SECRET_ACCESS_KEY=DUMMYEXAMPLEKEY SLS_DEBUG=* serverless offline start
Read table name
Check health table master
Table status: "ACTIVE"
Table master is ACTIVE
Check health serverless
Serverless status: 000
Serverless is not ACTIVE
Check health serverless
Serverless status: 000
Serverless is not ACTIVE
DEBUG[serverless-offline-sns]: starting plugin
DEBUG[serverless-offline-sns]: listening on 127.0.0.1:4002
DEBUG[serverless-offline-sns][server]: configuring route
DEBUG[serverless-offline-sns][adapter]: using endpoint: http://127.0.0.1:4002
DEBUG[serverless-offline-sns][adapter]: listing subs
DEBUG[serverless-offline-sns][adapter]: {"method":"POST","path":"/","headers":{"User-Agent":"aws-sdk-nodejs/2.1691.0 darwin/v20.9.0"},"body":"","endpoint":{"protocol":"http:","host":"127.0.0.1:4002","port":4002,"hostname":"127.0.0.1","pathname":"/","path":"/","href":"http://127.0.0.1:4002/"},"region":"ap-northeast-1","_userAgent":"aws-sdk-nodejs/2.1691.0 darwin/v20.9.0"}
DEBUG[serverless-offline-sns][server]: hello request
DEBUG[serverless-offline-sns][server]: {"Action":"ListSubscriptions","Version":"2010-03-31"}
DEBUG[serverless-offline-sns][server]: []
DEBUG[serverless-offline-sns][server]: []
DEBUG[serverless-offline-sns][server]: sending: <ListSubscriptionsResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
<ResponseMetadata>
<RequestId>8101fe23-ec4d-4ccb-bf58-88d112603102</RequestId>
</ResponseMetadata>
<ListSubscriptionsResult>
<Subscriptions>
</Subscriptions>
</ListSubscriptionsResult>
</ListSubscriptionsResponse>
DEBUG[serverless-offline-sns][server]: []
DEBUG[serverless-offline-sns][server]: []
DEBUG[serverless-offline-sns][adapter]: {"ResponseMetadata":{"RequestId":"fd25105d-5931-4a63-a7c1-171f300ff726"},"Subscriptions":[]}
DEBUG[serverless-offline-sns]: subs!: {"ResponseMetadata":{"RequestId":"fd25105d-5931-4a63-a7c1-171f300ff726"},"Subscriptions":[]}
DEBUG[serverless-offline-sns]: subscribing functions
DEBUG[serverless-offline-sns]: subscribing queues
DEBUG[serverless-offline-sns]: subscribe: http://localhost:9324/101010101010/task-action-queue
INFO[serverless-offline-sns]: Creating topic: "CqrsSnsTopic" for queue "http://localhost:9324/101010101010/task-action-queue"
DEBUG[serverless-offline-sns]: subscribe: http://localhost:9324/101010101010/notification-queue
INFO[serverless-offline-sns]: Creating topic: "CqrsSnsTopic" for queue "http://localhost:9324/101010101010/notification-queue"
DEBUG[serverless-offline-sns][server]: hello request
DEBUG[serverless-offline-sns][server]: {"Action":"CreateTopic","Name":"CqrsSnsTopic","Version":"2010-03-31"}
DEBUG[serverless-offline-sns][server]: []
DEBUG[serverless-offline-sns][server]: []
DEBUG[serverless-offline-sns][adapter]: arn: {"ResponseMetadata":{"RequestId":"afddff4d-77cb-4256-bf1c-34535c7b29ec"},"TopicArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic"}
DEBUG[serverless-offline-sns]: topic: {"ResponseMetadata":{"RequestId":"afddff4d-77cb-4256-bf1c-34535c7b29ec"},"TopicArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic"}
DEBUG[serverless-offline-sns][adapter]: subscribe: http://localhost:9324/101010101010/task-action-queue arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic
DEBUG[serverless-offline-sns][server]: hello request
DEBUG[serverless-offline-sns][server]: {"Action":"CreateTopic","Name":"CqrsSnsTopic","Version":"2010-03-31"}
DEBUG[serverless-offline-sns][server]: []
DEBUG[serverless-offline-sns][server]: []
DEBUG[serverless-offline-sns][adapter]: arn: {"ResponseMetadata":{"RequestId":"1bd437db-8daa-4caf-8ae4-47cf9bf95048"},"TopicArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic"}
DEBUG[serverless-offline-sns]: topic: {"ResponseMetadata":{"RequestId":"1bd437db-8daa-4caf-8ae4-47cf9bf95048"},"TopicArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic"}
DEBUG[serverless-offline-sns][adapter]: subscribe: http://localhost:9324/101010101010/notification-queue arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic
DEBUG[serverless-offline-sns][server]: hello request
DEBUG[serverless-offline-sns][server]: {"Action":"Subscribe","Attributes.entry.1.key":"RawMessageDelivery","Attributes.entry.1.value":"true","Attributes.entry.2.key":"FilterPolicy","Attributes.entry.2.value":"{\"action\":[\"task-execute\"]}","Endpoint":"http://localhost:9324/101010101010/task-action-queue","Protocol":"sqs","TopicArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic","Version":"2010-03-31"}
DEBUG[serverless-offline-sns][server]: []
DEBUG[serverless-offline-sns][server]: [{"SubscriptionArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic:558312","Protocol":"sqs","TopicArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic","Endpoint":"http://localhost:9324/101010101010/task-action-queue","Owner":"","Attributes":{"RawMessageDelivery":"true","FilterPolicy":"{\"action\":[\"task-execute\"]}"},"Policies":{"action":["task-execute"]}}]
DEBUG[serverless-offline-sns][adapter]: successfully subscribed queue "http://localhost:9324/101010101010/task-action-queue" to topic: "arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic"
DEBUG[serverless-offline-sns][server]: hello request
DEBUG[serverless-offline-sns][server]: {"Action":"Subscribe","Attributes.entry.1.key":"RawMessageDelivery","Attributes.entry.1.value":"true","Attributes.entry.2.key":"FilterPolicy","Attributes.entry.2.value":"{\"action\":[\"notification-action\",\"command-status\",\"task-status\"]}","Endpoint":"http://localhost:9324/101010101010/notification-queue","Protocol":"sqs","TopicArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic","Version":"2010-03-31"}
DEBUG[serverless-offline-sns][server]: [{"SubscriptionArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic:558312","Protocol":"sqs","TopicArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic","Endpoint":"http://localhost:9324/101010101010/task-action-queue","Owner":"","Attributes":{"RawMessageDelivery":"true","FilterPolicy":"{\"action\":[\"task-execute\"]}"},"Policies":{"action":["task-execute"]}}]
DEBUG[serverless-offline-sns][server]: [{"SubscriptionArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic:558312","Protocol":"sqs","TopicArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic","Endpoint":"http://localhost:9324/101010101010/task-action-queue","Owner":"","Attributes":{"RawMessageDelivery":"true","FilterPolicy":"{\"action\":[\"task-execute\"]}"},"Policies":{"action":["task-execute"]}},{"SubscriptionArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic:972218","Protocol":"sqs","TopicArn":"arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic","Endpoint":"http://localhost:9324/101010101010/notification-queue","Owner":"","Attributes":{"RawMessageDelivery":"true","FilterPolicy":"{\"action\":[\"notification-action\",\"command-status\",\"task-status\"]}"},"Policies":{"action":["notification-action","command-status","task-status"]}}]
DEBUG[serverless-offline-sns][adapter]: successfully subscribed queue "http://localhost:9324/101010101010/notification-queue" to topic: "arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic"
Offline Lambda Server listening on http://0.0.0.0:4000
serverless-offline-aws-eventbridge :: Plugin ready
serverless-offline-ses-v2: starting server...
serverless-offline-aws-eventbridge :: Mock server running at port: 4010
serverless-offline-ses-v2: server running at http://[::1]:8005
Starting Offline SQS at stage dev (ap-northeast-1)
Starting Offline Dynamodb Streams at stage dev (ap-northeast-1)
Starting Offline at stage dev (ap-northeast-1)
Offline [http for lambda] listening on http://0.0.0.0:3002
Function names exposed for local invocation by aws-sdk:
* main: serverless-example-dev-main
Configuring JWT Authorization: ANY /{proxy+}
┌──────────────────────────────────────────────────────────────────────┐
│ │
│ GET | http://0.0.0.0:3000/ │
│ POST | http://0.0.0.0:3000/2015-03-31/functions/main/invocations │
│ ANY | http://0.0.0.0:3000/swagger-ui/{proxy*} │
│ POST | http://0.0.0.0:3000/2015-03-31/functions/main/invocations │
│ ANY | http://0.0.0.0:3000/{proxy*} │
│ POST | http://0.0.0.0:3000/2015-03-31/functions/main/invocations │
│ │
└──────────────────────────────────────────────────────────────────────┘
Server ready: http://0.0.0.0:3000 🚀
Check health serverless
GET / (λ: main)
[Nest] 14434 - 2024/09/17 10:41:05 LOG [NestFactory] Starting Nest application...
(λ: main) RequestId: d4d764f6-e604-4d23-90a7-87ee0f457325 Duration: 855.64 ms Billed Duration: 856 ms
[Nest] 14434 - 2024/09/17 10:41:05 DEBUG [CommandService:local-demo-master-command] find data sync handlers from decorator +302ms
[Nest] 14434 - 2024/09/17 10:41:05 LOG [NestApplication] Nest application successfully started +1ms
[Nest] 14434 - 2024/09/17 10:41:05 DEBUG [AppController] ctx:: +4ms
[Nest] 14434 - 2024/09/17 10:41:05 DEBUG [AppController] {
"event": {
"body": null,
"cookies": [],
"headers": {
"host": "localhost:3000",
"user-agent": "curl/8.7.1",
"accept": "*/*"
},
"isBase64Encoded": false,
"pathParameters": null,
"queryStringParameters": null,
"rawPath": "/",
"rawQueryString": "",
"requestContext": {
"accountId": "offlineContext_accountId",
"apiId": "offlineContext_apiId",
"domainName": "offlineContext_domainName",
"domainPrefix": "offlineContext_domainPrefix",
"http": {
"method": "GET",
"path": "/",
"protocol": "HTTP/1.1",
"sourceIp": "127.0.0.1",
"userAgent": "curl/8.7.1"
},
"requestId": "offlineContext_resourceId",
"routeKey": "GET /",
"stage": "$default",
"time": "17/Sep/2024:10:41:04 +0900",
"timeEpoch": 1726537264747
},
"routeKey": "GET /",
"stageVariables": null,
"version": "2.0"
},
"context": {
"awsRequestId": "d4d764f6-e604-4d23-90a7-87ee0f457325",
"callbackWaitsForEmptyEventLoop": true,
"clientContext": null,
"functionName": "serverless-example-dev-main",
"functionVersion": "$LATEST",
"invokedFunctionArn": "offline_invokedFunctionArn_for_serverless-example-dev-main",
"logGroupName": "offline_logGroupName_for_serverless-example-dev-main",
"logStreamName": "offline_logStreamName_for_serverless-example-dev-main",
"memoryLimitInMB": "1024"
}
} +0ms
Serverless status: 200
Serverless is ACTIVE
Send a command to trigger command stream master
開発環境の構築が完了しました。