Ivan Roskoshnyi
05/21/2022, 1:48 PMREGION: stack.region,
USER_POOL_ID: auth.userPoolId,
IDENTITY_POOL_ID: auth.cognitoIdentityPoolId,
USER_POOL_CLIENT_ID: auth.userPoolClientId,
among lambda functions in SST?
My stacks are being called in the following way:
app
.stack(ApiStack)
.stack(StorageStack)
.stack(AuthStack)
.stack(SocketStack)
.stack(FrontendStack)
This is a new SST API so I had to use API Stack
in Auth Stack
via sst.use
What is interesting is API Stack
had being imported in Auth Stack
to attach permissions. BUT when I am trying to do smth like this:
const lambda = api.getFunction('POST /routeName')
lambda?.addEnvironment(
'USER_POOL_ID',
auth.userPoolId
)
I am getting the following error in the terminal
Error: 'dev-ApiStack' depends on 'dev-sst-AuthStack' (dev-sst-ApiStack -> dev-sst-AuthStack/Auth/UserPool/Resource.Ref, dev-sst-ApiStack -> dev-\sst-AuthStack/Auth/IdentityPool.Ref, dev-sst-ApiStack -> dev-sst-AuthStack/Auth/UserPoolClient/Resource.Ref). Adding this dependency (dev-sst-AuthStack -> dev-sst-ApiStack/API/Api/Resource.Ref) would create a cyclic reference.
Drew
05/22/2022, 5:57 AMDrew
05/22/2022, 5:57 AMDrew
05/22/2022, 5:58 AMDrew
05/22/2022, 5:59 AMDrew
05/22/2022, 5:59 AMIvan Roskoshnyi
05/22/2022, 6:59 AM.env
file. But this is a bad solution because I need to save DEV_variables & PROD_variables + using env.IS_LOCAL
to distinguish the environment etc.. I remember in SST versions 0.60x
it could be easily done. Hope someone can help me to find a better wayFrank
Ivan Roskoshnyi
05/25/2022, 8:08 AMFrank
auth.attachPermissionsForAuthUsers([api])
, this makes the AuthStack depends on the ApiStack, b/c AuthStack is creating an IAM role whose resources
field references the Api’s id.
• And when u do
lambda?.addEnvironment(
'USER_POOL_ID',
auth.userPoolId
)
this makes the ApiStack depends on the AuthStack, b/c ApiStack is creating a Lambda function whose environment
field references the User Pool’s id.
Hence the cyclic dependency. Both stacks need the other stack to be deployed first 😞Frank
AuthStack
and ApiStack
, this way Auth
and Api
are created within the same stack;
2. Or, store the User Pool ID to an SSM parameter. And have the Lambda function read the SSM parameter value at runtime.Frank
Drew
06/06/2022, 2:28 AMFrank
USER_POOL_ID
).Ivan Roskoshnyi
06/09/2022, 1:33 PMBrett Fieber
06/12/2022, 6:58 PM.stack(AuthStack)
to the top of the list in index.ts
• sst.use(AuthStack)
in ApiStack & StorageStack and attach the permissions in those stacks instead of using them in the AuthStack.
That would make the AuthStack generic and allow you to define how and what resources you apply it to in their respective stacks.