Julien Bras
12/02/2021, 3:17 PMNextJs
construct this week, and I found one nasty thing. I need to pass environment variables to the construct in order to provide Cognito User Pool Id and so but my Cognito User Pool is not built inside SST but in a different Cloudformation stack (with Serverless Framework). So I am using the Fn.importValue
but this is not working 😄:
// backend stack export prefix
const backendStackPrefix = `sls-cust-center-backend-${scope.stage}`;
console.log(`UserPool: ` + `${backendStackPrefix}-CognitoUserPool`);
console.log(`UserPool: ` + Fn.importValue(`${backendStackPrefix}-CognitoUserPool`));
// frontend application built using NextJs
new NextjsSite(this, "NextSite", {
path: "../frontend-next",
environment: {
NEXT_PUBLIC_API: Fn.importValue(`${backendStackPrefix}-ServiceEndpoint`),
NEXT_PUBLIC_COGNITO_REGION: this.region,
NEXT_PUBLIC_COGNITO_USER_POOL_ID: Fn.importValue(`${backendStackPrefix}-CognitoUserPool`),
NEXT_PUBLIC_COGNITO_APP_CLIENT_ID: Fn.importValue(`${backendStackPrefix}-CognitoUserPoolClient`),
NEXT_PUBLIC_COGNITO_DOMAIN: Fn.importValue(`${backendStackPrefix}-CognitoDomain`),
NEXT_PUBLIC_COGNITO_IDENTITY_POOL: Fn.importValue(`${backendStackPrefix}-CognitoIdentityPool`),
},
});
The value of the Fn.importValue
is something like ${Token[TOKEN.351]}
so it cannot be used for the next build
part of the NextJs
construct operation.
Do you know how to deal with that elegantly? (I was thinking of calling ListExportsCommand in the Stack but this is not elegant for sure!)
Thanks!Frank
NEXT_PUBLIC_API
are not available at build time.Frank
Frank
Frank
Julien Bras
12/03/2021, 9:32 PMNEXT_PUBLIC_...
) but at the end of the day we need to provide the info to the frontend 🙂 . Do you see how I can pass the variables in a different way? Thanks!Julien Bras
12/03/2021, 9:33 PM.env.local
file generated by the CI process in the nextjs folder.Frank
Frank
Julien Bras
12/04/2021, 3:34 PMFrank
Frank