SST doesn’t yet have a mirror for `sls logs` right...
# sst
b
SST doesn’t yet have a mirror for
sls logs
right? (ie. https://www.serverless.com/framework/docs/providers/aws/cli-reference/logs/#aws---logs)
f
Hey @Blake E, in
sst start
, the function code is run locally, and the logs are printed in the console.
Are you trying to look up log after u run
sst deploy
?
b
yes
sst start
and resulting lambda from
sst deploy
behave differently for me (I think it’s a reference to a static template file) but - I’m turning on accessLogs for my api now, and wanted an easy way to tail it.
and in practice, seeing what’s happening on the live deployment is useful
specifically, the nice feature of
sls logs
is that its function logGroup aware, so you can provide a simple arg like
functionName
and it finds the correct loggroup to tail.
f
Ah gotcha. Yeah, that makes sense.
Let me know if you manage to track down the static template file issue.
b
it’s a hunch, but I will
@Frank have confirmed it was a
.hbs
file not being included in lambda bundle - was using
fs.readFileSync
looking at other options now, like esbuild loaders
Copy code
ENOENT: no such file or directory, open './src/table.hbs'
f
Yeah, loader should work, and is recommended. If no luck, you can also try configuring the
bundle.copyFiles
options, like this https://docs.serverless-stack.com/constructs/Function#configure-bundling
b
yeah, I noticed copyFiles first, but I understand people do like the import style more these days.
@Frank (and others searching), bundle did work out just fine (although I still have //@ts-ignore at the import) but
Copy code
bundle: {
          loader: {
            '.hbs': 'text',
          },
        },
worked just fine
re: the tslint error for importing other files: https://medium.com/@sampsonjoliver/importing-html-files-from-typescript-bd1c50909992 worked just fine
For completedness - posting my end solution: using
lumigo-cli tail-cloudwatch-logs --namePrefix
and then added function logGroups to output for easier display and copy/pasta:
Copy code
const WebAndApi = new sst.Api(this, 'WebAndApi', { routes: ... })

const functionLogGroups = WebAndApi.routes
      .map((route) => {
        const fn = WebAndApi.getFunction(route)
        if (fn) {
          return {
            route,
            functionName: fn.functionName,
            functionArn: fn.functionArn,
            logGroup: fn.logGroup.logGroupName,
          }
        }
        return undefined
      })
      .filter((row) => row)

    this.addOutputs({
      ApiLogGroups: JSON.stringify(functionLogGroups, null, 2),
    })