dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.2k stars 793 forks source link

serverless offline does not work with aws: and ssm: variables #1647

Open lqueryvg opened 1 year ago

lqueryvg commented 1 year ago

Bug Report

It's impossible to work with serverless offline without connect to AWS if your serverless.yml file contains any variables which resolve from AWS (e.g. ${aws:accountId} or ${ssm:/some/path}).

You get errors like the following:

  - Cannot resolve variable at "custom.key1": AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://slss.io/aws-creds-setup>.,

The only workaround I've seen is to put all such variables in a separate file - and have a separate file for every environment. This is cludgey, nasty, horrible ....

Current Behavior

❯ yarn exec -- sls offline start
yarn exec v1.22.19
Environment: darwin, node 16.17.0, framework 3.23.0 (local), plugin 6.2.2, SDK 4.3.2
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Cannot resolve serverless.yml: Variables resolution errored with:
  - Cannot resolve variable at "custom.key1": AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://slss.io/aws-creds-setup>.,
  - Cannot resolve variable at "custom.key2": AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://slss.io/aws-creds-setup>.
error Command failed.
Exit code: 1
Command: sls
Arguments: offline start
Directory: <REDACTED>
Output:

info Visit https://yarnpkg.com/en/docs/cli/exec for documentation about this command.

Sample Code

service: testcase

plugins:
  - serverless-offline

provider:
  name: aws

custom:
  key1: ${aws:accountId}
  key2: ${ssm:/some/path}

Expected behavior/code

It should work like this:

  1. serverless-offline should have the common sense to not try to connect to an AWS service when running in offline mode - you shouldn't need to set AWS_PROFILE and configure dummy credentials in your .aws directory
  2. by default it should replace these variables with a default value, e.g. 123412341234 for the aws:accountId
  3. optionally it should be possible to override those default values via keys in the custom section of the serverless.yml

This is how plugins like serverless-offline-ssm and serverless-pseudo-parameters work. But the recommendation seems to be to use the native serverless features instead, despite the fact that they just don't work offline !

Environment

Framework Core: 3.23.0 (local) Plugin: 6.2.2 SDK: 4.3.2

Further information

This serverless-offline ticket was closed without action saying that this should be fixed in the core framework: https://github.com/dherault/serverless-offline/issues/1278

This serverless ticket says that this is a problem with serverless-offline: https://github.com/serverless/serverless/issues/11674

Someone needs to grab the bull by the horns on this one because the end user experience is that if you use the aws: variables recommended by the documentation, you simply can't use serverless offline without connecting to an AWS service of some kind.

nicolas-serbin commented 1 year ago

Can we have a solution for this .... ?

Drakula2k commented 1 year ago

It can be solved with plugin https://www.serverless.com/plugins/serverless-offline-ssm

lqueryvg commented 1 year ago

@Drakula2k ...

  1. the purpose of this ticket is to get the native ssm: behaviour fixed without introducing another package dependency
  2. what about aws: variables ?
Drakula2k commented 1 year ago

@lqueryvg yes, you're right, it doesn't completely solve the issue, only the ssm: case

throrin19 commented 1 year ago

Any news about that ? It's an important thing to override all aws: variables in offline config

thomas-meyer08 commented 1 year ago

I'm running into the same problem while upgrading from serverless 2 to 3. Is there any activity concerning this ticket?