can you not do this within `app.setDefaultFunction...
# help
s
can you not do this within
app.setDefaultFunctionProps()
?
Copy code
layers: [
      lambda.LayerVersion.fromLayerVersionArn(
        app,
        'KnexLayer',
        process.env.KNEX_LAYER_ARN
      ),
    ],
I’m getting: `Error: Import at 'KnexLayer' should be created in the scope of a Stack, but no Stack found`why have a
layers
array on that method then?
t
You can do this if you're inside a stack and pass the stack as the first arg to the layer
Basically this is tryign to create a resource (the layer) outside the context of a stack
s
ahh I see
well shoot. I actually do need this layer in all stacks
t
You shouldn't have a problem creating that in a base stack and setting that. It should work
s
so I suppose the core stack can import the layer, then pass that into the other stack constructors
t
I don't think you even need to pass it to other stack constructors unless you're referencing it
s
well, I need every single Lambda function to include it
across all 3 stacks
t
This maybe is a bit unclear but if you do
app.setDefaultFunctionProps
in one stack it applies to all functions everywhere
s
I thought we talked about this before, how
app.setDefaultFunctionProps
is app-wide, and can’t be set on a per-stack basis ?
t
It's the opposite problem, you can't set defaults for just one stack
anything you set there applies to all functions created after that call
s
ok..bear with me. so the situations I can call
app.setDefaultFunctionProps
are: 1. just once, at app level 2. for all stacks, and it must be all stacks, not 1/3 or 2/3
?
t
Not exactly for 2
Calling it at the stack level is the same as calling it at the app level
setDefaultFunctionProps
sets defaults globally everywhere regardless of where it's called
s
right.. ok. but you can’t define global
layers
at the app level. that has to be in a stack. but if I define that in my first stack, it should be available for all stacks & all funcs?
t
In this case you're actually doing 2 things 1. Creating a layer resource 2. setting global defaults It has to be done within a stack because of #1
correct
s
ok.. whew. thanks 😄