localstack / serverless-localstack

⚡ Serverless plugin for running against LocalStack
511 stars 82 forks source link

run interceptRequest async #219

Closed steffyP closed 1 year ago

steffyP commented 1 year ago

Issue: resolving the environment variable still sends the request to AWS, because reconfiguring the endpoint is running async, and is not finished when the getParameter SSM is called, resulting in error:

aws: [1] { UnrecognizedClientException: The security token included in the request is invalid.
    at Request.extractError (/path/ls-lambda/node_modules/aws-sdk/lib/protocol/json.js:52:27)
    at Request.callListeners (/path/ls-lambda/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/path/ls-lambda/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
   ....

'Cannot resolve serverless.yml: Variables resolution errored with:\n  - Cannot resolve variable at "provider.environment.LAMBDA_STAGE": The security token included in the request is invalid.',

This is triggered by the following configuration for LAMBDA_STAGE:

provider:
  name: aws
  runtime: nodejs18.x
  stage: dev
  region: eu-west-1
  memorySize: 512
  timeout: 60
  iam:
    role:
      statements:
        - Effect: 'Allow'
          Resource: '*'
          Action:
            - 'lambda:InvokeFunction'
            ....
  environment:
    LAMBDA_STAGE: ${ssm:/${opt:stage, self:provider.stage}/lambda/common/LAMBDA_STAGE}