0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Step Functions Local と AWS SAM CLI Local を使ってローカルで Step Functions の動作確認をする

Posted at

Step Functions および AWS SAM CLI Local - AWS Step Functions をもとに、 Step Functions Local の Docker 版を使って動かしたら動かなかったので、解決方法をメモしておきます。

Docker 版の Step Functions Local は設定ファイルが必要

Step Functions Local 設定のオプション - AWS Step Functions に記載の通り、 Docker 版の場合はこの設定ファイルを作成し、 docker run コマンド実行時に渡してあげる必要があります。

上記サンプルを動かす場合、アカウントや認証情報はダミーのものを使用するので、最低限 LAMBDA_ENDPOINT が設定されていれば大丈夫です。

LAMBDA_ENDPOINT の設定値

このサンプルでは、ローカルマシン内で AWS SAM CLI Local と Step Functions Local を両方立ち上げ、 Step Functions の実行コマンドを実行します(つまりターミナルのタブが3つ必要)。

このとき、 Step Functions Local の LAMBDA_ENDPOINT に、 jar 版と同様 http://localhost:3001 を指定すると、コンテナ内を見に行ってしまうため、以下のようなエラーが出てしまいます。

2020-07-06 09:14:33.725: CreateStateMachine => {...}
...
2020-07-06 09:14:44.416: arn:aws:states:us-east-1:123456789012:execution:HelloWorld:f0114461-f6fe-49b7-8cf5-24600c422160 : {"Type":"LambdaFunctionFailed","PreviousEventId":4,"LambdaFunctionFailedEventDetails":{"Error":"Lambda.SdkClientException","Cause":"Unable to execute HTTP request: Connect to localhost:3001 [localhost/127.0.0.1] failed: Connection refused (Connection refused)"}}
2020-07-06 09:14:44.426: arn:aws:states:us-east-1:123456789012:execution:HelloWorld:f0114461-f6fe-49b7-8cf5-24600c422160 : {"Type":"ExecutionFailed","PreviousEventId":5,"ExecutionFailedEventDetails":{"Error":"Lambda.SdkClientException","Cause":"Unable to execute HTTP request: Connect to localhost:3001 [localhost/127.0.0.1] failed: Connection refused (Connection refused)"}}

Docker for Mac を利用している場合、マニュアルに記載がある通り、 host.docker.internal というドメインでホストにアクセスすることが可能です。

したがって、 aws-stepfunctions-local-credentials.txt には以下のように記載します。

aws-stepfunctions-local-credentials.txt
LAMBDA_ENDPOINT=http://host.docker.internal:3001

なお、 docker-compose で上記環境(Step Functions Local や Lambda の実行環境)を構築する場合は、このホスト名の代わりに docker-compose 内で指定したホスト名を記載してください。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?