I'm looking to get on board with the new HTTP API ...
# sst
r
I'm looking to get on board with the new HTTP API and I've noticed the deployment behaviour is a bit different to the old REST API. With REST API I get a base URL that is suffixed with the stage. i.e. https://123lkjnd1.execute-api.eu-west-2.amazonaws.com/dev whereas with the HTTP API it's just https://123lkjnd1.execute-api.eu-west-2.amazonaws.com Is this an SST or CDK thing, or is this how HTTP APIs deployed in general? If the latter, what's the best practice for managing different stage deployments?
s
This looks to have a complete description of the behaviour you are describing: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-apigatewayv2-readme.html#publishing-http-apis
If you omit the 
stageName
 will create a 
$default
 stage. A 
$default
 stage is one that is served from the base of the API's URL - 
https://{api_id}.execute-api.{region}.<http://amazonaws.com/|amazonaws.com/>
r
Brilliant, thanks for that, I began my reading on the HTTP API, hadn't made it there yet.
I guess it'd be a good feature to wrap this into the SST Api construct
s
I think you can access the underlying api using the
htttpApi
prop: https://docs.serverless-stack.com/constructs/Api#configuring-the-http-api
r
Yeah, from the doc you shared it looks like a new HttpStage object needs to be created that references the API
s
Oh yeah, I see
It looks like api has an addStage function; but not sure what the behaviour will be
r
'Experimental' 😬
Actually seeing something's not quite right with this. I see my stage deployed in the console (as well as $default) but it's not callable. It just simply returns
Copy code
{
  "message": "Not Found"
}
where as the base/default URL does work. Maybe one for @Frank / @Jay
This when running via
sst start
Looking at the differences between the $default and dev stages, I see that there is no 'Attached deployment' for dev where as there is for $default
Ah, I see, you have to set autoDeploy: true on the httpStage
f
Hey @Ross Coundon, yeah, when you the $default stage with HTTP API, you get a clean url without the stage name at the end.
Are you trying to setup multiple API stages?
r
No, when I get Seed set up, each Seed stage will have its own deployment. It's just a useful visual guide to have the stage in the URL
f
Ah I see. Did you get it to work using?
r
Yeah, setting autoDeploy seemed to do the trick
f
So you have 2 stages, the $default stage and one with the name of SST stage?
Ah I see you can do something like this:
Copy code
new Api(this, "Api", {
  httpApi: {
    createDefaultStage: false,
  },
  routes: {
    ...
  },
});
^^btw if you have access log turned on, you might want to check if logs are written in your CloudWatch logs. Let me know if it’s not working, I might need make a change.
r
No problem. I'll try this tomorrow
I actually get an error when I try adding the
Copy code
httpApi: {
        createDefaultStage: false,
      },
i.e.
Copy code
const api = new Api(this, 'TheStack', {
      defaultAuthorizationType: ApiAuthorizationType.CUSTOM,
      defaultAuthorizer: new HttpLambdaAuthorizer({
        authorizerName: 'FirebaseAuthorizer',
        handler: firebaseAuthHandler,
      }),
      accessLog: true,
      cors: {
        allowHeaders,
        allowOrigins: ['*'],
        allowMethods: [CorsHttpMethod.GET, <http://CorsHttpMethod.POST|CorsHttpMethod.POST>],
      },
      httpApi: {
        createDefaultStage: false,
      },
TypeError: Cannot read property 'api' of undefined at Object.buildAccessLogData (/Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/@serverless-stack/resources/src/util/apiGatewayV2AccessLog.ts7954) Setting
accessLog: false
Makes the error go away
f
Ah I see. So right now u have both the $default and the custom stage right?
r
No, with
Copy code
httpApi: {
        createDefaultStage: false,
      },
and
Copy code
accessLog: false,
Just the custom stage gets created
f
But that gives u an error right?
r
Sorry, corrected example
f
Got it. We should get access log working for you. Opened an issue to track this https://github.com/serverless-stack/serverless-stack/issues/492