serverless-offline
serverless-offline copied to clipboard
serverless offline does not work with aws: and ssm: variables
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
- file: serverless.yml
service: testcase
plugins:
- serverless-offline
provider:
name: aws
custom:
key1: ${aws:accountId}
key2: ${ssm:/some/path}
Expected behavior/code
It should work like this:
- 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 - by default it should replace these variables with a default value, e.g.
123412341234
for theaws:accountId
- 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.
Can we have a solution for this .... ?
It can be solved with plugin https://www.serverless.com/plugins/serverless-offline-ssm
@Drakula2k ...
- the purpose of this ticket is to get the native
ssm:
behaviour fixed without introducing another package dependency - what about
aws:
variables ?
@lqueryvg yes, you're right, it doesn't completely solve the issue, only the ssm:
case
Any news about that ? It's an important thing to override all aws:
variables in offline config
I'm running into the same problem while upgrading from serverless 2 to 3. Is there any activity concerning this ticket?