https://serverless-stack.com/ logo
#help
Title
# help
m

Mischa Spiegelmock

12/05/2021, 2:28 PM
how do I add a default VPC to my functions? I have to create the VPC first but I’m getting
Default function props for the stack must be set before any resources have been added.
f

Frank

12/06/2021, 6:09 PM
Hey @Mischa Spiegelmock, do you have any functions created before the creation of the VPC?
m

Mischa Spiegelmock

12/06/2021, 6:09 PM
no functions I think just VPC. it’s at the top of my stack
f

Frank

12/06/2021, 6:09 PM
I see.
@thdxr should we make the
setDefaultFunctionProps
callable before any `Function`s are created, instead of any resources are created?
What @Mischa Spiegelmock is trying to do is quite common, I think we should allow it. What do you think?
m

Mischa Spiegelmock

12/06/2021, 6:12 PM
what I ended up doing is subclassing Function
and then I do
Copy code
if (db) {
      this.getAllFunctionsWithDatabaseAccess().forEach((func) => {
        func.addEnvironment(EnvVars.databaseUrl, db.makeDatabaseUrl())
        func.connections.allowTo(db, Port.tcp(5432), "DB access")
at the end
t

thdxr

12/06/2021, 6:57 PM
Yeah I ran into this the other day with vpc
It's a good idea
f

Frank

12/07/2021, 2:56 AM
Submitted a PR. Will merge after tests pass.
m

Mischa Spiegelmock

12/07/2021, 6:56 AM
amazing thank you!
f

Frank

12/07/2021, 7:58 PM
Hey guys, this is supported in v0.53.4. You can call
setDefaultFunctionProps
as long as a Function hasn’t been added.