<@U01REA1NTM1> has inspired me to start the proces...
# sst
r
@Tyler Flint has inspired me to start the process of migrating our flagship product from serverless framework to sst. We’re using ReST API rather than HTTP API, so does this mean that I can’t use the import capability described here? I.e. I’d need to define a CDK API Gateway construct in the SST stack and define all my lambda integration methods and roots there rather than being able to migrate one by one and import the ones I’m not ready to migrate into the SST stack?
f
Hey @Ross Coundon Yeah, import won’t work b/c
sst.Api
expects an HTTP API. Instead, if you are fine with using HTTP API, you can create an
sst.Api
in SST and migrate route by route over from ur existing REST API. But you mentioned you are actually using the usage plan and api key features, so I guess this won’t work for you. If that’s the case, let’s add REST API support in SST. Defining CDK API Gateway constructs isn’t the end of the world… but very cumbersome. I think I can have something by mid next week. Does that work for you timeline wise?
r
Frankly, that’d be amazing
f
For a v1, if you can import the REST API, keeping custom domain, usage page, api key, access log, etc configurations still in Serverless Framework, but you can start adding routes in SST. Would that make sense?
Or what would be a good first step for u guys?
r
The main thing for us is to get live debugging in place. So importing the API and defining the lambdas incrementally in SST would be good
f
Sounds good.
Hey @Ross Coundon Just released v0.10.9 with REST API support, the construct is called
sst.ApiGatewayV1Api
You can import your current API like this. You would need to find out the
restApiId
and
rootResourceId
of your API. And if you are adding more routes in SST, you need to also import the parent paths.
Copy code
new sst.ApiGatewayV1Api(this, "Api", {
  restApi: apigateway.fromRestApiAttributes(this, "IRestApi", {
    restApiId,
    rootResourceId,
  }),
  importedPaths: {
    "/notes": "slx2bn",
  },
  routes: {
    "GET    /notes/{noteId}": "src/getNote.main",
    "UPDATE /notes/{noteId}": "src/updateNote.main",
  },
});
Let me know if this makes sense. Btw, here are some more examples - https://docs.serverless-stack.com/constructs/ApiGatewayV1Api
r
Fantastic, thanks Frank, I’ll take a look. Hoping to start the migration next week if I can clear the decks
Just a quick question on the import example
Copy code
new ApiGatewayV1Api(this, "Api", {
  restApi: apigateway.fromRestApiAttributes(this, "MyRestApi", {
    restApiId,
    rootResourceId,
  }),
  importedPaths: {
    "/notes": "slx2bn",
    "/users": "uu8xs3",
  },
  routes: {
    "GET /notes/{noteId}": "src/getNote.main",
    "GET /users/{userId}": "src/getUser.main",
  },
});
I assume the restApiId would be the Id that takes the form of something like ‘d4txxxxxxx’ but what is the rootResourceId? Also, what do slx2bn and uu8xs3 refer to in the example is it related to what you’d see in the console here?
f
so
wil2fry
is equivalent to
slx2bn
in the example
r
Cool, I see. Thanks. Sorry if this is basic, to import those values from an existing API defined in serverless framework, how do I get hold of them?
f
You can add something like this to your
serverless.yml
to have these values printed out as stack output and optionally export them
Copy code
resources:
  - Outputs:
      ApiGatewayRestApiId:
        Value:
          Ref: ApiGatewayRestApi
    
      ApiGatewayRestApiRootResourceId:
        Value:
           Fn::GetAtt:
            - ApiGatewayRestApi
            - RootResourceId 

      ApiGatewayRestApiNotesResourceId:
        Value:
          Ref: ApiGatewayResourceNotes
r
perfect, thank you
f
Oh one thing to add, you might be aware of this already, REST API routes are structured like a tree.
/
is the root
/notes
is a child of
/
/users
is another child of
/
/notes/${noteId}
is a child of
/notes
/notes/${noteId}/authors
is a child of
/notes/${noteId}
So if u want to add a route, and if it’s parent already exists in ur current API, u need to import the parent.
That’s what
importedPaths
is for.
r
Got ya