We're getting an error when setting accessLogs to ...
# sst
r
We're getting an error when setting accessLogs to true on the Api construct. If we set
accessLog: true
in the snippet below we get the error:
Copy code
TypeError: Cannot read property 'api' of undefined
    at Object.buildAccessLogData (/home/jamin/Code/OFSC-forms-PDFify/node_modules/@serverless-stack/resources/src/util/apiGatewayV2AccessLog.ts:79:54)
    at new Api (/home/jamin/Code/OFSC-forms-PDFify/node_modules/@serverless-stack/resources/src/Api.ts:217:45)
    at new PdflifierStack (/home/jamin/Code/OFSC-forms-PDFify/lib/PdflifierStack.ts:97:17)
    at Object.main (/home/jamin/Code/OFSC-forms-PDFify/lib/index.ts:13:3)
    at Object.<anonymous> (/home/jamin/Code/OFSC-forms-PDFify/.build/run.js:89:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)

There was an error synthesizing your app.
It goes away if we set it to false. Any thoughts on what's going on here?
t
When does this error happen?
r
When running
Copy code
sst start --stage local --increase-timeout
@Ben Gooding
t
Hm it shouldn't even be getting there if accessLog = false
This is on latest sst?
Let me try and recreate
b
Copy code
"@serverless-stack/cli": "0.40.1",
    "@serverless-stack/resources": "0.40.1",
t
Hm couldn't recreate. I'm looking at the Api construct where the error happens and the code that it's hitting shouldn't be hit if
accessLog === false
Oh I misread you're issue, you're only seeing this if it's set to true
@Frank I'm not super familiar with the Api construct but it looks like their default stage is undefined
Ah it's because
createDefaultStage: false
ok. @Ross Coundon @Ben Gooding the access log currently looks for the default stage and since it's turned off that's why it's erroring
r
Right, why can't you have access logs without a default stage?
this may well be my lack of knowledge of the HTTP API 😄
t
Yeah my knowledge is weak here but looking at the code it looks like the default stage is used to generate the log group name (which we can probably work around) and is pointed to the access log. I'm not really familiar with api stages so reading up on that quickly
I think if you specify the accessLog field as a apig.CfnStage.AccessLogSettingsProperty you may work around this bug
Eh but that would require you creating your own log group. Let me wait for frank to chime in, just need to know what to assume when there's no default stage
Are you guys creating your own stage somewhere?
r
yeah, we do
Copy code
new HttpStage(this, 'Stage', {
      httpApi: api.httpApi,
      stageName,
      autoDeploy: true,
    });
t
Ah ok. So the issue with the current implementation is when the Api is created with accessLog on it needs to know what stage to build the log for. Right now it assumes it's the defaultStage. Thinking we might need to add a
stages
prop to api so you can create it inline and accessLog: true can create one for each stage
does that create any issues in your setup?
r
No, that would make sense
t
Made a ticket here if you want to follow along: https://github.com/serverless-stack/serverless-stack/issues/742
Will get to it this week
r
Fantastic, thanks Dax