Skip to content

run interceptRequest async#219

Merged
steffyP merged 10 commits intomasterfrom
fix_ssm_parameter_resolving
May 5, 2023
Merged

run interceptRequest async#219
steffyP merged 10 commits intomasterfrom
fix_ssm_parameter_resolving

Conversation

@steffyP
Copy link
Member

@steffyP steffyP commented Apr 28, 2023

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}
  • It turns out, that in this case (for resolving the environment variable) the intercept-hook interceptRequest is triggered

    • the function interceptRequest is a patching aws.request, which is alreadyasync.
    • changing function to async interceptRequest, and adding await for the aws-reconfiguration.
    • added init hook that will also await the aws-reconfiguration
  • changed the default for BUCKET_MARKER_LOCAL to hot-reload

@steffyP steffyP changed the title [wip] run interceptRequest async run interceptRequest async May 5, 2023
@steffyP steffyP marked this pull request as ready for review May 5, 2023 09:19
@steffyP steffyP requested a review from whummer May 5, 2023 09:19
Copy link
Member

@whummer whummer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great set of changes @steffyP ! 🚀 Kudos for digging into this deep rabbit hole. I think with this approach we now have a solid solution that enables async logic (to resolve the target endpoint (IPv4/IPv6 switch) properly in an async way) and proper initialization of the plugin with the initialize hook. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants