```export const RUNTIME = Runtime.NODEJS_16_X; ...
# general
m
Copy code
export const RUNTIME = Runtime.NODEJS_16_X;
    this.setDefaultFunctionProps({
      vpc,
      runtime: RUNTIME,
})
It would be nice if this worked - I want to reuse the runtime instance for the buildImage property but
runtime
wants just a string now 😞
r
runtime
is looking for a
Runtime
just not the same one you're using 🙂 the SST
Runtime
is a type only. I would think something like this would be safe enough though?
Copy code
import type { Runtime as SST_RUNTIME } from '@serverless-stack/resources'
import { Runtime } from 'aws-cdk-lib/aws-lambda'

export default function (app: App) {
  const RUNTIME = Runtime.NODEJS_16_X

  app.setDefaultFunctionProps({
    runtime: RUNTIME.toString() as SST_RUNTIME,
  })
}
m
because that
Runtime
is just a discriminated string type and I need stuff like the
bundlingImage
that comes with the CDK
Runtime
r
So not sure I am following. The
runtime
prop for
setDefaultFunctionProps
takes a SST Runtime (various strings), so you would set that using
toString()
but then you would still have
RUNTIME
to pass around and do whatever with to get access to the other things you need? Maybe I am not following where you want to use
RUNTIME
? Do you need it as a variable in your function? or just need it in the stack where the function is? Also for the record I think there is a documentation/implementation bug here. @thdxr I am pinging you as I am not sure who else to raise this up to. According to the docs
runtime
should be able to take a
string
or a
cdk.lambda.Runtime
https://docs.serverless-stack.com/constructs/v0/Function#runtime However the ts types have it like this
Copy code
/**
     * The runtime environment. Only runtimes of the Node.js, Python, Go, and .NET (C# and F#) family are supported.
     *
     * @default "nodejs14.x"
     *
     * @example
     * ```js
     * new Function(stack, "Function", {
     *   runtime: "nodejs16.x",
     * })
     *
*/ runtime?: Runtime;``` Where
Runtime
there is
Copy code
export declare type Runtime = "nodejs" | "nodejs4.3" | "nodejs6.10" | "nodejs8.10" | "nodejs10.x" | "nodejs12.x" | "nodejs14.x" | "nodejs16.x" | "python2.7" | "python3.6" | "python3.7" | "python3.8" | "python3.9" | "dotnetcore1.0" | "dotnetcore2.0" | "dotnetcore2.1" | "dotnetcore3.1" | "go1.x";
Maybe it should be this ? I am not sure if this code is implemented though
Copy code
runtime?: Runtime | lambda.Runtime;
m
lambda.Runtime is more than just a string.
it contains more information
like what bundling image to use when building stuff
r
yeah thats why i imported them both up here
Copy code
import type { Runtime as SST_RUNTIME } from '@serverless-stack/resources'
import { Runtime } from 'aws-cdk-lib/aws-lambda'
SST_RUNTIME
is for SST then
Runtime
would be for you to do whatever you need with.
g
Doing
RUNTIME.name
should work since it is the actual string value, might have to do
RUNTIME.name as sst.Runtime
or however sst exports the type.
r
Yup
name
or
toString()
should get you there. you will need to cast it though as
runtime
is not typed as a string in SST. unless you're not using TS at all, then i guess none of this matters haha. So like i had in the original example
Copy code
runtime: RUNTIME.toString() as SST_RUNTIME,
m
yeah, i can probably do that, seems wack IMO?