You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Issues referencing CloudFormation outputs in Serverless YML #4702
I am trying to reference CloudFormation outputs in my Serverless yaml file so that I can reference existing resources created in other services/stacks.
e.g. role: ${cf:BaseSecurity.LambdaKinesisExecutionRole}
This seemed to work fine until I tried to change my provider region to include a default value;
region: ${opt:region, ‘eu-west-1’}
After adding this my info and deploy fail with the following;
Hi @JBartlett86 , it seems that the variable resolution with defaults does not resolve properly but instead keeps the serverless variable notation. This might be a generic issue or it might be restricted to the region property.
Can you check, if the defaults resolution works for other properties than region, i.e. try to populate something else with ${opt:region, 'us-west-1'} and see it that is set correctly by using serverless print?
I am also using the same default syntax for stage (e.g. ${opt:stage, 'research'}) and that works perfectly fine when I use print and remove the region one.
If I remove the use of ${cf:x.y} from my serverless yml file the region variable resolution begins to work again and I no longer need to supply --region eu-west-1.
As a test I decided to just try variable resolution without the default part so I created a single property and referenced that from region;
custom:
x: eu-west-1
region: ${self:custom.x}
On running serverless print without --region it failed again except this time saying;
I wonder if the code processing CloudFormation references (e.g. ${cf:x.y}) is using region but not expecting to have to do variable resolution?
Yeah, that's it. Variables themselves will wait for other variables to be resolved they depend on. But the CF resolution itself is dependent on the region, without explicitly referencing it (as it is used in the code).
Instead of using this.options.region as region parameter, the CF resolution code must use ${self:provider.region} for it's region, push it to the currently running variable resolution and await it's result. Then it shall work for all cases.
BTW: The same issue most likely exists for SSM resolution
I think this is related to an issue that I'm having with my CloudFormation variables.
I get Profile ${self:custom.profile} does not exist when I try to deploy a serverless function that uses CF resolution to get the ARN of another stack's stream.
My provider configuration relies on the variable ${self:custom.profile}, and my custom variables are loaded from a file. When I debug through the code that fetches the values from CF, it assumes that the provider has been initialised and that all of its variables have been resolved. This is not the case, as the custom variables from the file have not yet been resolved and I get the error above.
Here is my custom: custom: ${file(serverless.env.yml):${opt:stage}}
And then in serverless.env.yml there is a value like:
prod:
profile: awsProfileName
Here's a stack trace, with some parts removed, and path obscured:
Error: Profile ${self:custom.profile} does not exist
at Object.addProfileCredentials (proj/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:85:15)
at AwsProvider.getCredentials (proj/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:289:12)
at AwsProvider.request (proj/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:198:30)
at Variables.getValueFromCf (proj/node_modules/serverless/lib/classes/Variables.js:352:8)
at Variables.getValueFromSource (proj/node_modules/serverless/lib/classes/Variables.js:199:22)
at property.match.forEach (proj/node_modules/serverless/lib/classes/Variables.js:120:29)
at Array.forEach (native)
at Variables.populateProperty (proj/node_modules/serverless/lib/classes/Variables.js:111:41)
at BbPromise.all.then (proj/node_modules/serverless/lib/classes/Variables.js:131:24)
I am using v1.26.0.
It seems likely that the two issues are related, but if they aren't I am happy to create a new issue.
during deploy, after Safeguards checks, it raise the same error:
Serverless: Recoverable error occurred (Inaccessible host: `cloudformation.'. This service may not be available in the `${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}' region.), sleeping for 5 seconds. Try 1 of 4
Serverless: Recoverable error occurred (Inaccessible host: `cloudformation.'. This service may not be available in the `${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}' region.), sleeping for 5 seconds. Try 2 of 4
Serverless: Recoverable error occurred (Inaccessible host: `cloudformation.'. This service may not be available in the `${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}' region.), sleeping for 5 seconds. Try 3 of 4
Serverless: Recoverable error occurred (Inaccessible host: `cloudformation.'. This service may not be available in the `${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}' region.), sleeping for 5 seconds. Try 4 of 4
Serverless: Publishing service to the Serverless Dashboard...
Serverless: Recoverable error occurred (Inaccessible host: `cloudformation.'. This service may not be available in the `${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}' region.), sleeping for 5 seconds. Try 1 of 4
Serverless: Recoverable error occurred (Inaccessible host: `cloudformation.'. This service may not be available in the `${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}' region.), sleeping for 5 seconds. Try 2 of 4
Serverless: Recoverable error occurred (Inaccessible host: `cloudformation.'. This service may not be available in the `${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}' region.), sleeping for 5 seconds. Try 3 of 4
Serverless: Recoverable error occurred (Inaccessible host: `cloudformation.'. This service may not be available in the `${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}' region.), sleeping for 5 seconds. Try 4 of 4
ServerlessError: Inaccessible host: `cloudformation.'. This service may not be available in the `${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}' region.
at promise.catch.err (/usr/local/lib/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:316:27)
at process._tickCallback (internal/process/next_tick.js:68:7)
Serverless Error ---------------------------------------
Inaccessible host: `cloudformation.'. This service may not be available in the `${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}' region.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: linux
Node Version: 10.16.3
Framework Version: 1.51.0
Plugin Version: 1.3.11
SDK Version: 2.1.0
Activity
mizalewski commentedon Jan 31, 2018
Hi,
I see that you use Serverless 1.25.0. Can you check is problem still exists with latest version (1.26.0 released 2 days ago on npm)?
JBartlett86 commentedon Feb 1, 2018
Hi,
I just upgraded and am getting the same error;
Serverless Error ---------------------------------------
Inaccessible host:
cloudformation.'. This service may not be available in the${opt:region, 'eu-west-1'}' region.Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless
Your Environment Information -----------------------------
OS: darwin
Node Version: 9.4.0
Serverless Version: 1.26.0
HyperBrain commentedon Feb 1, 2018
Hi @JBartlett86 , it seems that the variable resolution with defaults does not resolve properly but instead keeps the serverless variable notation. This might be a generic issue or it might be restricted to the region property.
Can you check, if the defaults resolution works for other properties than region, i.e. try to populate something else with
${opt:region, 'us-west-1'}and see it that is set correctly by usingserverless print?JBartlett86 commentedon Feb 2, 2018
Hi,
I am also using the same default syntax for stage (e.g.
${opt:stage, 'research'}) and that works perfectly fine when I use print and remove the region one.If I remove the use of ${cf:x.y} from my serverless yml file the region variable resolution begins to work again and I no longer need to supply --region eu-west-1.
As a test I decided to just try variable resolution without the default part so I created a single property and referenced that from region;
On running
serverless printwithout --region it failed again except this time saying;I wonder if the code processing CloudFormation references (e.g.
${cf:x.y}) is using region but not expecting to have to do variable resolution?Thanks,
John
HyperBrain commentedon Feb 2, 2018
Yeah, that's it. Variables themselves will wait for other variables to be resolved they depend on. But the CF resolution itself is dependent on the region, without explicitly referencing it (as it is used in the code).
Instead of using
this.options.regionas region parameter, the CF resolution code must use${self:provider.region}for it's region, push it to the currently running variable resolution and await it's result. Then it shall work for all cases.BTW: The same issue most likely exists for SSM resolution
mriccid commentedon Feb 13, 2018
I think this is related to an issue that I'm having with my CloudFormation variables.
I get
Profile ${self:custom.profile} does not existwhen I try to deploy a serverless function that uses CF resolution to get the ARN of another stack's stream.My provider configuration relies on the variable
${self:custom.profile}, and my custom variables are loaded from a file. When I debug through the code that fetches the values from CF, it assumes that the provider has been initialised and that all of its variables have been resolved. This is not the case, as the custom variables from the file have not yet been resolved and I get the error above.Here is my custom:
custom: ${file(serverless.env.yml):${opt:stage}}And then in
serverless.env.ymlthere is a value like:Here's a stack trace, with some parts removed, and path obscured:
I am using v1.26.0.
It seems likely that the two issues are related, but if they aren't I am happy to create a new issue.
JBartlett86 commentedon Feb 16, 2018
HI,
Just interested if there is any update on this?
Thanks,
John
daaru00 commentedon Sep 5, 2019
Hi,
I confirm that is an error related to region variable interpolation, I'm using this syntax:
during deploy, after Safeguards checks, it raise the same error:
Doing a little bit of debug (adding log before https://github.com/serverless/serverless/blob/master/lib/plugins/aws/provider/awsProvider.js#L316) I discovered that the AWS API call the raise and error is:
describeStackswith parameters{ StackName: 'myapp-database-demo' }.I printed out
this.sdkconfigurations and here the issue:so this envolve every CloudFormation call, not only other staks outputs, even deploy is broken,
medikoo commentedon Apr 12, 2021
Closing as this issue is fixed with new variable resolver, which ensures that core properties are resolved for variable sources that depend on them