I’m building a CDK stack using a CI/CD pipeline and encountering a puzzling issue with AppSync resolvers. The deployment proceeds smoothly when I utilize appsync.SchemaFile.fromAsset()
to retrieve my GraphQL schema from a local file. However, the build fails when I attempt to use appsync.Code.fromAsset()
for the resolver functions, resulting in a file not found error. The error message states: > Error: Cannot find asset at /home/runner/work/MyProject/MyProject/src/resolvers/createItem.js Here’s my CDK code: javascript const graphqlApi = new appsync.GraphqlApi(this, 'MyApi', { name: 'my-graphql-api', definition: { schema: appsync.SchemaFile.fromAsset('src/graphql/schema.graphql') }, authorizationConfig: { defaultAuthorization: { authorizationType: appsync.AuthorizationType.USER_POOL, userPoolConfig: {userPool: cognitoUserPool}, }, additionalAuthorizationModes: [ {authorizationType: appsync.AuthorizationType.API_KEY} ] }, }); const dynamoDataSource = graphqlApi.addDynamoDbDataSource('itemsTable', itemsTable); new appsync.Resolver(this, 'createItemResolver', { api: graphqlApi, fieldName: 'createItem', typeName: 'Mutation', code: appsync.Code.fromAsset('src/resolvers/createItem.js'), dataSource: dynamoDataSource, runtime: appsync.FunctionRuntime.JS_1_0_0, });
Why does the schema file work while the resolver code file doesn’t, even though they are in similar directory structures?
hey, just wanted to add that sometimes CI/CD environments can have different working directories. double-check if you’re pointing to the correct path! and yeah, check the case sensitivity too, it messes with stuff lots of times.
Had this exact problem about six months ago with our CI/CD pipeline. CDK handles different asset types differently - schema files just get copied as-is, but resolver code goes through extra processing that’s more sensitive to file system issues. Turned out my resolver files were getting excluded during CI builds because of a gitignore pattern catching JavaScript files in certain directories. Fixed it by double-checking that all resolver files made it into the build artifacts and making sure the relative paths matched between local and CI environments. I’d suggest adding some debug output to verify the working directory and file existence right before CDK deployment runs.