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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can no longer deploy Cloudformation where API Gateway is in a different file than the Lambda #335

Closed
saratitan opened this issue Mar 19, 2018 · 4 comments

Comments

@saratitan
Copy link

saratitan commented Mar 19, 2018

We had to separate our API Gateway put it in one file (api.yaml) and have our lambdas in another (serverless.yaml), and then have the API being a imported value in serverless.yaml

  BaseRequest:
    Type: AWS::Serverless::Function
    Properties:
      ...
      Events:
        GetResource:
          Type: Api
          Properties:
            RestApiId:
              Fn::ImportValue:
                !Sub ${Service}-apigateway-${Environment}
            Path: /{countryId}/{path}
            Method: GET
        PostResource:
          Type: Api
          Properties:
            RestApiId:
              Fn::ImportValue:
                !Sub ${Service}-apigateway-${Environment}
            Path: /{countryId}/{path}
            Method: POST

This was never an issue up until a week ago, where we now receive the following error:

Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [BaseRequest] is invalid. Event with id [PostResource] is invalid. RestApiId must be a valid reference to an 'AWS::Serverless::Api' resource in same templatemake

One option would be to move the depending Lambda to api.yaml but we would like to have all of our Lambdas together in one file.

@saratitan saratitan changed the title Can no longer deploy Cloudformation where API Gateway is in another file Can no longer deploy Cloudformation where API Gateway is in a different file than the Lambda Mar 19, 2018
@ashwgupt
Copy link

ashwgupt commented Apr 1, 2018

Is this error fixed for you?

What wonders me the most is that, how did you ever made it working as we couldn't ever extract our API Gateway out from the SAM Template file as the SAM would fail with error "The RestApiId must be a valid reference of serverless:api type resource in the same template file".

Would you mind sharing your Api gateway SAM file (or did you use plain CF and not SAM) that you used to create the Api Gateway?

@saratitan
Copy link
Author

saratitan commented Apr 4, 2018

We tried to redeploy today and we received the same error as before, so the issue has not been resolved.

This is our api.yaml:

  ApiGateway:
    Type: AWS::Serverless::Api
    Properties:
      StageName: !Ref Environment
      DefinitionBody:
        Fn::Transform:
          Name: AWS::Include
          Parameters:
            Location: !Ref Swagger

Outputs:
  ApiGatewayRef:
    Description: ...
    Value: !Ref ApiGateway
    Export:
      Name: !Sub ${Service}-apigateway-${Environment}

The exported value is then referenced in the lambda resource as seen in the original post.

We had this on two projects and both stopped working. One of the projects was in production so it caused us a bit of a problem.

@jadamsdb
Copy link

jadamsdb commented Nov 2, 2018

Any updates on what you did to resolve this (if you did)? Running into the same issues.

@brettstack
Copy link
Contributor

We currently only support !Ref for RestApiId. We'll update documentation to reflect this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants