Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create basepath mapping when using Fn::ImportValue for restApiId in serverless.yml #219

Closed
sampsasaarela opened this issue Apr 25, 2019 · 7 comments 路 Fixed by #220 or #380
Labels

Comments

@sampsasaarela
Copy link
Contributor

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Bug Report

Error Description
I have defined restApiId in my serverless.yml like this:

provider:
  apiGateway:
    restApiId:
      Fn::ImportValue: api-${opt:stage, self:provider.stage}-restApiId

But after upgrading to version 3.2.1 it fails. The previous version use Cloudformation but 3.x uses api, so now it fails because restApiId is not available as it has defined as an object.

Command Run
sls deploy

Console Output

Serverless: [AWS apigateway 200 1.501s 0 retries] getBasePathMappings({ domainName: 'example.com' })
Serverless: [AWS apigateway undefined 0.002s 0 retries] createBasePathMapping({ basePath: '(none)',
  domainName: 'api.staging-coinland.com',
  restApiId: { 'Fn::ImportValue': 'api-dev-restApiId' },
  stage: 'dev' })
Serverless Domain Manager: InvalidParameterType: Expected params.restApiId to be a string
 
  Error --------------------------------------------------
 
  Error: Unable to create basepath mapping.

Versions

  • Domain Manager version(s): 3.2.1
  • Node/npm version: Node 8
  • Serverless Version: 1.41.1
@sampsasaarela sampsasaarela changed the title Can get basepath mappings when using Fn::ImportValue in serverless template Can't get basepath mappings when using Fn::ImportValue in serverless template Apr 25, 2019
@sampsasaarela sampsasaarela changed the title Can't get basepath mappings when using Fn::ImportValue in serverless template Unable to create basepath mapping when using Fn::ImportValue for restApiId in serverless template Apr 25, 2019
@sampsasaarela sampsasaarela changed the title Unable to create basepath mapping when using Fn::ImportValue for restApiId in serverless template Unable to create basepath mapping when using Fn::ImportValue for restApiId in serverless.yml Apr 25, 2019
@sampsasaarela
Copy link
Contributor Author

I made PR#220 which will resolve this issue.

@captainsidd
Copy link
Contributor

Hi there! Thanks for doing this - sorry we've been behind on responding to these issues/PRs. We'll try to get to this soon.

@YurgenUA
Copy link

Hi there!
Would be really good go proceed with mentioned PR as I came across this issue too.

Leaving a workaround which I did (DO not like adding extra sls-plugin :( )
In serverless.yml:

  1. add new plugin
    plugins:
  • serverless-cloudformation-sub-variables
  1. make restApiId to have string (not CF object) value
    provider:
    apiGateway:
    restApiId: #{!Ref ApiGatewayRestApi}

In my case, I already have defined _ ApiGatewayRestApi_ as AWS::ApiGateway::RestApi in resource section of serverless.yml, and I think that in TC case whole ImportValue can be put as well

@ripley
Copy link

ripley commented Nov 16, 2019

Given the fix has not been merged after months, looks like stating #220 as dependency is the way to go :(

@aelayeb
Copy link

aelayeb commented Nov 27, 2019

Still no news on this issue ?
I got the same error with a simple reference to a RestApi declared in resources section of the same serverless.yml config file.

@aelayeb
Copy link

aelayeb commented Nov 27, 2019

Hi there!
Would be really good go proceed with mentioned PR as I came across this issue too.

Leaving a workaround which I did (DO not like adding extra sls-plugin :( )
In serverless.yml:

1. add new plugin
   plugins:


* serverless-cloudformation-sub-variables


1. make _restApiId_ to have string (not CF object) value
   provider:
   apiGateway:
   restApiId: #{!Ref ApiGatewayRestApi}

In my case, I already have defined _ ApiGatewayRestApi_ as AWS::ApiGateway::RestApi in resource section of serverless.yml, and I think that in TC case whole ImportValue can be put as well

This didn't work for me, does it still work in your project with latest versions (3.3.0) ?
Got this error:
An error occurred: ApiGatewayResourceRi - Invalid API identifier specified 519444591809:${Ref ApiGW} (Service: AmazonApiGateway; Status Code: 404; Error Code: NotFoundException; Request ID: 2b8258cd-6ecc-4892-80ad-91f46f6c8702).

"ApiGW" is the name of the CF resource "AWS::ApiGateway::RestApi".
Currently I don't have a workaround and must manage pathMapping manually :(

@thomasviaud
Copy link

Hello I encountered the same issue on this. My ApiGateway is defined in an additional stack. I found a fix by referencing restApiId with the ${cf:} helper instead of ImportValue :

apiGateway:
    restApiId: ${cf:MY_STACK.MY_VARIABLE}
    ...

https://serverless.com/framework/docs/providers/aws/guide/variables#reference-cloudformation-outputs

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