Reference more than one api as variable/enviroment in serverless.yml

Hello everyone,
i’m trying to use serverless to publish my aws service. I’ve 3 different lambdas, a sqs queue and 2 api gateway (one for api server and another one for a websocket implementation). I’m trying to get the url reference for my api gateways. I’ve read some of the question already answered here and a blog post (How to I get my API Gateway URL with the Serverless Framework). Don’t know if is me but nothing seams to work.

This is a piece of my file:

service: test-serverless

custom:
  region: region
  stage: test

provider:
name: aws
runtime: nodejs8.10
profile: default
region: ${self:custom.region}
stage: ${self:custom.stage}
memorySize: 1024
timeout: 30
websocketsApiName: websocket-name-test-serverless
websocketsApiRouteSelectionExpression: $request.body.message

package:
individually: true

resources:  # CloudFormation template syntax
Resources:
    sqsQueue:
    Type: "AWS::SQS::Queue"
    Properties:
        QueueName: "sqs-test"

functions:
WebSocketApi:
    handler: handler.js
    environment:
    API_CLIENT_STAGE: ${self:custom.stage}
    API_CLIENT_URL: env.GW_URL
    TABLE_NAME: tablename
    SQS_URL: https://sqs.eu-west-1.amazonaws.com/#{AWS::AccountId}/sqs-test 
        WS_ENDPOINT: ws_endpoint
    package:
    include:
        - handler.js
    events:
    - websocket: $connect
    - websocket: $disconnect
    - websocket: $default
sqs:
    handler: handler.js
    environment:
    API_CLIENT_URL: TODO_PUT_URL_HERE
    API_WS_URL: TODO_PUT_URL_HERE
    package:
    include:
        - handler.js
    events:
    - sqs:
        arn:
        Fn::GetAtt:
            - sqsQueue
            - Arn
ApiGatewayRestApi:
    handler: handler.js
enviroment:

    API_CLIENT_URL: TODO_PUT_URL_HERE
    API_WS_URL: TODO_PUT_URL_HERE
package:
include:
    - handler.js
events:
#LOGIN
- http:
    method: post
    path: /auth/token
    integration: lambda
    methodResponses:
    -
        StatusCode: 200
        ResponseModels: {}
    -
        StatusCode: 401
        ResponseModels: {}
    -
        StatusCode: 403
        ResponseModels: {}

thanks

i’ve managed to get the url of the api doing so:

custom:
  region: eu-west-1
  stage: prod
  apigatewayurl: 
    Fn::Join:
    - ""
    - - Ref: "ApiGatewayRestApi"
      - ".execute-api."
      - ${self:provider.region}
      - "."
      - Ref: "AWS::URLSuffix"
      - "/"
      - ${self:provider.stage}

and then in my enviroment: API_CLIENT_URL: ${self:custom.apigatewayurl}

I’m still trying to figure out how to get the ref of the OTHER api gateway (the websocket)

Posting this for anyone in my situation.

Thanks

Have you had any luck outputting the WS gateway endpoint now? I’ve been running into the same issue as you and have been unable to find any related docs.

No luck yet, I’ve manage to put only one WS gateway endpoint as showed a couple of post above, but still can’t find anything to reference the websocket.
For now i’ve just put a placeholder and then change it manually.

Maybe all the websocket thing is a little bit premature in serverless? or I’m missing something bit time

Hello, I asked the same question here and got an answer by another user that solved my problem:

hope you find this useful.

Cheers and thanks to this wonderful community!

That’s pretty close to what I ended up with as well! My laptop was out of commission while traveling over the weekend so wasn’t able to follow up. Thanks so much for sharing!