Skip to content

Issues referencing CloudFormation outputs in Serverless YML #4702

Closed

Description

@JBartlett86

Bug Report

Description

Hi,

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;

Serverless Error ---------------------------------------

Inaccessible host: cloudformation.'. This service may not be available in the${opt:region, ‘eu-west-1’}’ region.

Your Environment Information -----------------------------
OS: darwin
Node Version: 9.4.0
Serverless Version: 1.25.0

I can fix the issue by calling

serverless info --region eu-west-1

however I would prefer not to always be forced to supply a region if possible.

Any help would be greatly appreciated.

Thanks,
John

see: https://forum.serverless.com/t/issues-referencing-cloudformation-outputs-in-serverless-yml/3646

Activity

  1. mizalewski commented on Jan 31, 2018

    @mizalewski

    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)?

  2. JBartlett86 commented on Feb 1, 2018

    @JBartlett86
    Author

    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

  3. HyperBrain commented on Feb 1, 2018

    @HyperBrain
    Contributor

    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?

  4. JBartlett86 commented on Feb 2, 2018

    @JBartlett86
    Author

    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;

    custom:
      x: eu-west-1
    
    region: ${self:custom.x}
    

    On running serverless print without --region it failed again except this time saying;

    Serverless Error ---------------------------------------

    Inaccessible host: cloudformation.'. This service may not be available in the ${self:custom.x}' 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

    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

  5. HyperBrain commented on Feb 2, 2018

    @HyperBrain
    Contributor

    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

  6. mriccid commented on Feb 13, 2018

    @mriccid

    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.

  7. JBartlett86 commented on Feb 16, 2018

    @JBartlett86
    Author

    HI,

    Just interested if there is any update on this?

    Thanks,
    John

  8. daaru00 commented on Sep 5, 2019

    @daaru00
    Contributor

    Hi,

    I confirm that is an error related to region variable interpolation, I'm using this syntax:

    provider:
      name: aws
      profile: ${opt:profile, env:SERVERLESS_PROFILE}
      runtime: nodejs10.x
      stage: ${opt:stage, env:SERVERLESS_STAGE, 'demo'}
      region: ${opt:region, env:SERVERLESS_REGION, 'eu-west-1'}

    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
    

    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: describeStacks with parameters { StackName: 'myapp-database-demo' }.

    I printed out this.sdk configurations and here the issue:

    region: '${opt:region, env:SERVERLESS_REGION, \'eu-west-1\'}',
    endpoint: 'cloudformation.${opt:region, env:SERVERLESS_REGION, \'eu-west-1\'}.amazonaws.com',
    

    so this envolve every CloudFormation call, not only other staks outputs, even deploy is broken,

  9. medikoo commented on Apr 12, 2021

    @medikoo
    Contributor

    Closing as this issue is fixed with new variable resolver, which ensures that core properties are resolved for variable sources that depend on them

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions