hey guys, I’m running into an issue trying to migr...
# help
s
hey guys, I’m running into an issue trying to migrate past 0.42. I have this in one of my stack constructors:
Copy code
app.setDefaultFunctionProps({
      layers: [
        lambda.LayerVersion.fromLayerVersionArn(
          this,
          'KnexLayer',
          process.env.KNEX_LAYER_ARN
        ),
      ],
    });
of course, you can no longer call this method more than once. the problem is, if I try to move this into the main index.ts and add it to that
setDefaultFunctionProps
call, I get:
Copy code
Error: Import at 'KnexLayer' should be created in the scope of a Stack, but no Stack found
how do I solve this? EDIT: oh.. hang on. I think there’s a stack-level
setDefaultFunctionProps
now
nope. using
this.setDefaultFunctionProps
in the stack, I get:
Copy code
Error: Default function props for the stack must be set before any resources have been added. Use 'addDefaultFunctionEnv' or 'addDefaultFunctionPermissions' instead to add more default properties.
this is a bit confusing. this is literally before any resource gets created, it’s the first stack that gets set up
t
Yeah this layer thing is confusing there's a few options
Use the callback form of
app.setDefaultFunctionProps(stack =>
that'll give you access to the stack so you can attach the layer to it
s
in the stack, right? not the app level code
t
In the app
s
ahh gotcha
t
Copy code
stack => {
      layers: [
        lambda.LayerVersion.fromLayerVersionArn(
          stack,
          'KnexLayer',
          process.env.KNEX_LAYER_ARN
        ),
      ],
    }
something like that
s
but if it’s app level, what stack is that referring to? all of them?
t
Yeah it'll insert it into all of them
s
ok. that’s ok, because I use Knex in most of my app
t
since this is an imported layer it won't actually be creating anything so shouldn't slow anything down
I'm also adding
app.addDefaultFunctionLayers([...])
in the next release so that you can import the layer once in a stack and add it as a default. This is probably more useful for layers you need to build yourself (eg prisma)
s
it could be used for imported layers too though, right?
t
yeah it can
s
cool. I’ll probably switch to that later, just because it’s more straightforward
the stack’s deploying now.. seems to have worked. thanks! 🙂 then I’ll give the source map thing a try
oh.. I noticed I’m on 0.43.3. so the full path update is in here?
t
no it's only in that canary build I dm'd you
not released yet
s
ah ok
will try that real quick