Mischa Spiegelmock
05/25/2022, 12:02 AMexport 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 😞Ross Gerbasi
05/25/2022, 3:32 AMruntime
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?
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,
})
}
Mischa Spiegelmock
05/25/2022, 5:11 AMRuntime
is just a discriminated string type and I need stuff like the bundlingImage
that comes with the CDK Runtime
Ross Gerbasi
05/25/2022, 2:30 PMruntime
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
/**
* 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
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
runtime?: Runtime | lambda.Runtime;
Mischa Spiegelmock
05/25/2022, 4:39 PMMischa Spiegelmock
05/25/2022, 4:39 PMMischa Spiegelmock
05/25/2022, 4:39 PMRoss Gerbasi
05/25/2022, 4:40 PMimport 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.Garret Harp
05/25/2022, 4:42 PMRUNTIME.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.Ross Gerbasi
05/25/2022, 4:47 PMname
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
runtime: RUNTIME.toString() as SST_RUNTIME,
Mischa Spiegelmock
05/25/2022, 6:22 PM