https://serverless-stack.com/ logo
#sst
Title
# sst
j

Justin Kasad

03/07/2021, 2:15 AM
Hi everyone, quick question regarding hybrid apps on seed.run. I’m currently migrating my serverless framework (built using serverless-stack v3) to SST. I created a new service on seed for the SST service and have existing seed services for the serverless.yml services. The deploy succeeds but the SST service is being deployed to a different endpoint (I use
CfnOutput
to output the endpoint and see it in the logs) How do I get the SST service to deploy to the same endpoint as the serverless.yml services? The same one that seed.run returns after building. Thank you for your help!
f

Frank

03/07/2021, 2:39 AM
Hey @Justin Kasad, do you mean you want the SST app to reuse an existing Api endpoint that was created in a Serverless Framework service?
j

Justin Kasad

03/07/2021, 2:51 AM
Yes I believe so. I’m automatically building when a PR is opened, and seed.run deploys the PR to an endpoint, but the SST service is not on that endpoint and is instead on its own endpoint. This is my current workflow
f

Frank

03/07/2021, 2:52 AM
I see. Are you using the
sst.Api
construct to create the Api endpoint in SST currently?
j

Justin Kasad

03/07/2021, 2:53 AM
Yes, its basically straight out of the example
Copy code
export default class MyStack extends sst.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    // Create the HTTP API
    const api = new sst.Api(this, "Api", {
      routes: {
        "GET /house/{id}": "src/get.getHouse",
      },
    });

    api.attachPermissions(sst.PermissionType.ALL);

    // Show API endpoint in output
    new cdk.CfnOutput(this, "ApiEndpoint", {
      value: api.httpApi.apiEndpoint,
    });
  }
}
so sst.Api will create its own endpoint, separate from the one that seed.run makes?
f

Frank

03/07/2021, 2:54 AM
So instead of creating a new endpoint, you can pass an existing Api Gateway HTTP Api endpoint to
sst.Api
and SST will use that instead of creating a new one
j

Justin Kasad

03/07/2021, 3:00 AM
Ok that makes sense, but how do i get the HTTP api endpoint that seed generates from (i think) my serverless.yml file? I see an example of how to get/share the endpoint from other sst.Api, but not exactly sure how to get it from serverless
Thank you for your help!
f

Frank

03/07/2021, 3:08 AM
one way you can do it would be to have the
root-api
service export the api endpoint as
${stage}-api-endpoint
And in ur sst app:
Copy code
new Api(this, "Api", {
  httpApi: apigatewayv2.fromHttpApiAttributes(this, "MyHttpApi", {
    httpApiId: cdk.Fn.import_value(`${stage}-api-endpoint`).substring(8, 18),
  }),
  routes: {
    "GET /notes": "src/list.main",
  },
});
ie. you have stage called pr123,
root-api
will export the deployed endpoint ie.
pr123-api-endpoint
with value
<https://mhb5fkpgx9.execute-api.us-east-1.amazonaws.com>
Then the sst app imports
pr123-api-endpoint
, parses out
mhb5fkpgx9
from the endpoint, and use that to import the Api Gateway HTTP Api
Let me know if that makes sense.
j

Justin Kasad

03/07/2021, 3:16 AM
Thank you! I’ll try it soon and let you know!
f

Frank

03/07/2021, 3:17 AM
yup.. oh btw.. i should’ve asked this first.. are you using http api or rest api in your serverless.yml?
SST only works with HTTP api at the moment, and can’t import an existing REST api
j

Justin Kasad

03/07/2021, 7:22 PM
ah, I’m definitely using a REST api. I was planning on converting everything to SST and was able to successfully debug locally, but I wanted to make sure everything would work smoothly with seed.run before investing time in converting all the API endpoints.
f

Frank

03/08/2021, 4:25 AM
Ah yeah. Feel free to ping me if you run into any hiccups. Txt me at +16478061629 if urgent.