Filip Pyrek [AWS Hero]
06/18/2022, 1:06 PMimport { someFunction } from '@packages/some-package' // or import from '../../packages/some-package' - it's is the same in this case
export const handler = async (event) => {
someFunction('hello')
return '123'
}
Then I start the debugging session with $ sst start
When I change the file of the lambda function handler, I can see in the terminal info message:
Functions: Building api functions/lambda.handler...
Functions: Done building api functions/lambda.handler (101ms)
And everything works great so far. π
The problem:
When I change a file inside the package @packages/some-package
which is located in completely different folder (../../packages/some-package
), no reload/recompilation happens and the application is still using the old source code of the package.
How I hacked it and fixed it:
When I did the reverse engineering, I found out that here:
https://github.com/serverless-stack/serverless-stack/blob/9d8cc00da72942ef39348b25ff993117e502f30f/packages/core/src/runtime/watcher.ts
and here:
https://github.com/serverless-stack/serverless-stack/blob/9d8cc00da72942ef39348b25ff993117e502f30f/packages/core/src/runtime/handler/node.ts#L2[β¦]24
the SST is defining which files it will be watching.
When I added to the list path to my packages folder, it started to work β
What do you think would be the best way how to address this issue? Iβm happy to contribute. π
Thanks.thdxr
06/18/2022, 1:12 PMthdxr
06/18/2022, 1:19 PMthdxr
06/18/2022, 1:19 PMFilip Pyrek [AWS Hero]
06/18/2022, 1:31 PMthdxr
06/18/2022, 1:32 PMthdxr
06/18/2022, 1:33 PMFilip Pyrek [AWS Hero]
06/18/2022, 1:46 PMpackage.json
. Or is there something more to it? Some faster compile times or something like that?thdxr
06/18/2022, 1:52 PMthdxr
06/18/2022, 1:53 PMFilip Pyrek [AWS Hero]
06/18/2022, 2:29 PM.
βββ api
β βββ functions
β β βββ lambda.ts // this is the Lambda
β βββ package.json
β βββ schema.graphql
β βββ tsconfig.json
βββ frontend
β βββ README.md
β βββ next-env.d.ts
β βββ next.config.js
β βββ package.json
β βββ public
β βββ styles
β βββ tsconfig.json
βββ package-lock.json
βββ package.json
βββ packages
β βββ some-package
β βββ package.json
β βββ src
β β βββ index.ts
β βββ tsconfig.json
βββ sst.json
βββ stacks
β βββ API.ts
β βββ Frontend.ts
β βββ index.ts
βββ tsconfig.json
βββ vitest.config.ts
There are two services - API an Frontend - which are split into two SST stacks.
Workspaces configuration
"workspaces": [
"api",
"frontend",
"packages/*"
],
So the some-package
package is not inside the api
and thatβs the reason why the changes are not captured.
And because in future there will be more backend services/stacks (containing Step Functions, DynamoDB tables etc.) I want to be able to use the packages inside all the backend services (=stacks) - not just in the API.thdxr
06/18/2022, 2:33 PMthdxr
06/18/2022, 2:33 PMthdxr
06/18/2022, 2:34 PMthdxr
06/18/2022, 2:35 PMthdxr
06/18/2022, 2:35 PMthdxr
06/18/2022, 2:37 PMcore
folder is the same as your some-package
folderthdxr
06/18/2022, 2:37 PMFilip Pyrek [AWS Hero]
06/18/2022, 2:37 PMapi
folder is the base folder?
It it because I use set it inside the stack?
export function ApiStack({ stack }: StackContext): void {
stack.setDefaultFunctionProps({
srcPath: 'api'
})
thdxr
06/18/2022, 2:38 PMFilip Pyrek [AWS Hero]
06/18/2022, 2:50 PMapi
folder to backend
. letβs say
I set it in the stack like this:
export function ApiStack({ stack }: StackContext): void {
stack.setDefaultFunctionProps({
srcPath: 'backend'
})
then I will have to address my API like this:
new AppSyncApi(stack, 'GraphqlApi', {
schema: 'api/schema.graphql',
dataSources: {
notesDS: 'api/functions/lambda.handler',
notesDS1: 'api/functions/lambda.handler',
notesDS2: 'api/functions/lambda.handler',
notesDS3: 'api/functions/lambda.handler',
notesDS4: 'api/functions/lambda.handler',
notesDS5: 'api/functions/lambda.handler',
notesDS6: 'api/functions/lambda.handler',
},
resolvers: {
'Query listNotes': 'notesDS',
}
})
which means that I will have to include the api
folder prefix in all file names.
and then when I will want to create another stack
export function OtherStack({ stack }: StackContext): void {
stack.setDefaultFunctionProps({
srcPath: 'backend'
})
and have source files inside backend/otherApi
It will have to have the folder also in the file names:
new AppSyncApi(stack, 'GraphqlApi', {
schema: 'otherApi/schema.graphql',
dataSources: {
notesDS: 'otherApi/functions/lambda.handler',
notesDS1: 'otherApi/functions/lambda.handler',
notesDS2: 'otherApi/functions/lambda.handler',
notesDS3: 'otherApi/functions/lambda.handler',
notesDS4: 'otherApi/functions/lambda.handler',
notesDS5: 'otherApi/functions/lambda.handler',
notesDS6: 'otherApi/functions/lambda.handler',
},
resolvers: {
'Query listNotes': 'notesDS',
}
})
And in that case, it seems like the default srcPath
βsugarβ is not that helpful anymore.
So I tried to do change the default srcPath
to .
export function ApiStack({ stack }: StackContext): void {
stack.setDefaultFunctionProps({
srcPath: '.'
})
and that makes my current setup with the packages reloading work fine π π
So let me try to work with it a bit, so that I can check whether everything works for me in such setup.thdxr
06/18/2022, 2:53 PMsrcPath
is more than just an alias, it's actually used by sst to understand where your project "starts"Filip Pyrek [AWS Hero]
06/18/2022, 2:53 PMsrcPath
to .
? Arenβt there going to be any issues like βCDK code vs. the lambda codeβ or something like that?
I will rather create the backend
folder and move all the stuff there.. so that I can make sure that correct tsconfig etc. is being used there.
So I will do it as youβve suggested π πthdxr
06/18/2022, 2:53 PMthdxr
06/18/2022, 2:53 PMFilip Pyrek [AWS Hero]
06/18/2022, 7:37 PMthdxr
06/21/2022, 8:08 PMapi
to services
to avoid the confusion