serverless-localstack icon indicating copy to clipboard operation
serverless-localstack copied to clipboard

variables in profile name breaks sls logs

Open yonahforst opened this issue 4 years ago • 6 comments

I'm getting some strange behavior when i have serverless variables in my profile name, like this:

custom:
  defaultStage: local
  stage: ${opt:stage, self:custom.defaultStage}
  localstack:
    stages:
      - local
    lambda:
      mountCode: True

provider:
  profile: ${self:custom.stage}Profile
  ....

Depending on the command and the parameters, I'll sometimes get Error: Profile ${self:custom.stage}Profile does not exist

  • sls deploy works perfectly.
  • sls deploy -s local throws the error
  • sls print works perfectly.
  • sls print -s local throws the error

sls logs works differently. if i call it without the stage variable, it tries to call the real aws endpoint

  • sls logs -f myFunc throws The security token included in the request is invalid..
  • sls print -s local throws the profile error

┆Issue is synchronized with this Jira Task by Unito

yonahforst avatar May 21 '20 10:05 yonahforst

Thanks for reporting @yonahforst . This should be fixed in a7189808717cff31aae3f8252167e1375d79d432 - can you please give it another try with the latest version 0.4.26? Please report here if the problem persists. Thanks

whummer avatar Aug 26 '20 21:08 whummer

@whummer i think this fix causes the aws endpoints to never be reconfigured.

I get errors saying that the stack/log-group doesn't exist. I assume that's because the endpoints weren't reconfigured and sls is still trying to talk to the real aws endpoint

yonahforst avatar Aug 27 '20 08:08 yonahforst

Thanks for the update @yonahforst . Haven't been able to reproduce this (seems to be working for the examples we tested). Can you please share a small, complete example to reproduce this issue? Thanks!

whummer avatar Aug 27 '20 09:08 whummer

sure thing @whummer :)

  • add profile called localProfile to your ~/.aws/credentials
  • run sls to create a new service
  • replace the yml file with this:
service: temp1

custom:
  defaultStage: local
  stage: ${opt:stage, self:custom.defaultStage}
  localstack:
    host: http://${env:LOCALSTACK_HOST, 'localhost'}
    edgePort: ${env:LOCALSTACK_EDGE_PORT, '4566'}
    stages:
      - local

provider:
  name: aws
  runtime: nodejs12.x
  region: eu-west-1
  stage: ${self:custom.stage}
  profile: ${self:custom.stage}Profile

functions:
  hello:
    handler: handler.hello

plugins:
  - serverless-localstack  
  • run sls deploy
  • run sls info. You should get Stack with id temp1-local does not exist
  • run sls logs -f hello. you should get The specified log group does not exist.

yonahforst avatar Aug 27 '20 09:08 yonahforst

Thanks for the update @yonahforst . Looks like your Serverless stack is using eu-west-1 - just to confirm, are you seeing the same error if you configure DEFAULT_REGION=eu-west-1 in the environment of your LocalStack Docker container? Thanks

whummer avatar Aug 27 '20 20:08 whummer

hi @whummer, yes I already have DEFAULT_REGION=eu-west-1 set 🙂

I think the problem is here: https://github.com/localstack/serverless-localstack/blob/a7189808717cff31aae3f8252167e1375d79d432/src/index.js#L104-L111 if this.reconfigureAWS() fails as is said it might, then those endpoints never get reconfigured and stay set to the real aws endpoints

yonahforst avatar Aug 28 '20 17:08 yonahforst

Hi @yonahforst,

do you still have issues with variable resolvment with the latest localstack-serverless plugin?

steffyP avatar Oct 13 '23 15:10 steffyP

This issue seems to be stale. As we didn't get any response in two months, and the original report is from 2020, we are closing this issue now. Please feel free to reopen if it still persists, and provide updates logs and details.

steffyP avatar Dec 15 '23 10:12 steffyP