在本地测试步骤函数时出错:请求中包含的安全令牌无效

Error testing step function locally: The security token included in the request is invalid

我正在尝试在本地测试阶跃函数。我已经定义了我的 stateMachine.json 并添加了我的凭据(aws_access_key_idaws_secret_access_key)和 aws configure .

我正在按照以下步骤 运行 状态机:https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-lambda.html。但是当我开始执行时,我得到这个错误:

2021-08-08 05:37:56.464: arn:aws:states:us-east-1:123456789012:execution:StateMachine:firstTest : {"Type":"LambdaFunctionFailed","PreviousEventId":4,"LambdaFunctionFailedEventDetails":{"Error":"Lambda.AWSLambdaException","Cause":"The security token included in the request is invalid. (Service: AWSLambda; Status Code: 403; Error Code: UnrecognizedClientException; Request ID: 66622740-bcbc-4397-8c97-75454dca550d; Proxy: null)"}}

可能是哪个错误?

您需要将环境变量 LAMBDA_ENDPOINT 设置为 host.docker.internal


Step 3,你 运行 这个命令:

sam local start-lambda

输出如下:

...
* Running on http://127.0.0.1:3001/ (Press CTRL+C to quit)

记住3001,下面会用到

然后,参考Step Functions Local configuration options。 它说,aws-stepfunctions-local-credentials.txt 包含凭据。

包括 LAMBDA_ENDPOINT=http://host.docker.internal:3001.

凭证文件示例:

AWS_ACCOUNT_ID= ...
AWS_DEFAULT_REGION= ...
AWS_ACCESS_KEY_ID= ...
AWS_SECRET_ACCESS_KEY= ...
LAMBDA_ENDPOINT=http://host.docker.internal:3001