Hi everyone, quick question regarding hybrid apps ...
# sst
j
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
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
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
I see. Are you using the
sst.Api
construct to create the Api endpoint in SST currently?
j
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
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
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
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
Thank you! I’ll try it soon and let you know!
f
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
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
Ah yeah. Feel free to ping me if you run into any hiccups. Txt me at +16478061629 if urgent.