After update to SST v0.60 (CDK v2), any CfnInclude...
# help
a
After update to SST v0.60 (CDK v2), any CfnInclude fails to synthesize with this odd error:
Copy code
Error: ENOENT: no such file or directory, open '/Users/adam/dev/casa/cloud/.build/cfn-types-2-classes.json'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at Object.readJsonSync (/Users/adam/dev/casa/node_modules/aws-cdk-lib/cloudformation-include/lib/file-utils.ts:5:27)
    at loadCfnTypeToL1Mapping (/Users/adam/dev/casa/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-type-to-l1-mapping.ts:24:17)
    at Object.lookup (/Users/adam/dev/casa/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-type-to-l1-mapping.ts:17:26)
    at CfnInclude4.getOrCreateResource (/Users/adam/dev/casa/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.ts:503:49)
    at new CfnInclude4 (/Users/adam/dev/casa/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.ts:93:12)
    at new IotDeviceStack (/Users/adam/dev/casa/cloud/src/stacks/iot-device/iot-device.stack.ts:17:5)
    at Object.main (/Users/adam/dev/casa/cloud/src/stacks/index.ts:117:23)
    at Object.<anonymous> (/Users/adam/dev/casa/cloud/.build/run.js:94:16)
Code snippets:
Copy code
import { CfnInclude } from "aws-cdk-lib/cloudformation-include";

    new CfnInclude(this, "iot-device-stack", {
      templateFile: "src/stacks/iot-device/iot-device.yaml",
      parameters: {
        namespace: prefix.substring(0, prefix.length - 1),
      },
    });
t
what version were you on before?
a
0.57
t
this must be something with cdkv2 then right
a
That's what I figure. Path problem perhaps though. cfn-types-2-classes.json should be in node_modules somewhere, not .build
Yup, found in
node_modules/aws-cdk-lib/cloudformation-include/cfn-types-2-classes.json
I assume this is an esbuild issue of not resolving the right path. I'll have to revert back to 0.57; this is a total blocker. 😞
t
this is failing on
sst build
right
a
yes
In https://github.com/aws/aws-cdk/blob/v2-release/packages/%40aws-cdk/cloudformation-include/lib/cfn-type-to-l1-mapping.ts
Copy code
function loadCfnTypeToL1Mapping() {
  return futils.readJsonSync(path.join(__dirname, "..", "cfn-types-2-classes.json"))
}
The .json file is indeed one directory up from this source in node_modules, but at runtime this is executing from
.build/lib/index.js
f
@thdxr would marking
aws-cdk-lib
as an esbuild external module resolve this?
t
Ah
That's possible
f
Hey @Adam Fanello I just checked that all dependencies in
package.json
are set to external when bundling with esbuild. Can you check if you have
aws-cdk-lib
listed in your
package.json
(the one in the same folder as
sst.json
)?
a
It is not. Here's the whole file:
Copy code
{
  "name": "@pkg/cloud",
  "version": "1.0.0",
  "description": "Serverless project for AWS Lambdas written in Typescript",
  "author": "Onica",
  "private": true,
  "scripts": {
    "analyze": "npm run build && npm run lint && npm test && prettier -c . --ignore-path ../.prettierignore",
    "clean": "rm -rf .build .sst cdk.out coverage dist",
    "lint": "eslint src",
    "test": "jest",
    "test:watch": "jest --watch --runInBand",
    "start": "sst start --stage $DEPLOY_ENVIRONMENT",
    "build": "tsc && sst build --stage $DEPLOY_ENVIRONMENT",
    "deploy": "sst deploy --stage $DEPLOY_ENVIRONMENT",
    "remove": "sst remove --stage $DEPLOY_ENVIRONMENT",
    "run:script": "ts-node --transpile-only"
  },
  "dependencies": {
    "@aws-sdk/client-ssm": "^3.45.0",
    "@aws/dynamodb-batch-iterator": "^0.7.1",
    "@aws/dynamodb-query-iterator": "^0.7.1",
    "@middy/core": "^2.5.4",
    "@middy/http-cors": "^2.5.4",
    "@middy/http-event-normalizer": "^2.5.4",
    "@middy/http-header-normalizer": "^2.5.4",
    "@middy/http-json-body-parser": "^2.5.4",
    "@sailplane/expiring-value": "^2.0.0",
    "@sailplane/injector": "^2.0.1",
    "@sailplane/lambda-utils": "^4.0.0",
    "@sailplane/logger": "^3.0.0",
    "@sailplane/state-storage": "^2.0.0",
    "bottlejs": "^1.7.2",
    "http-errors": "^1.8.1",
    "jsonwebtoken": "^8.5.1",
    "jwk-to-pem": "^2.0.5",
    "node-fetch": "^2.6.6",
    "node-forge": "^0.10.0",
    "temporal-constants": "^1.1.2",
    "temporal-types": "^1.2.0"
  },
  "devDependencies": {
    "@serverless-stack/cli": "0.60.4",
    "@serverless-stack/resources": "0.60.4",
    "@stoplight/spectral-cli": "^6.1.0",
    "@types/aws-lambda": "^8.10.89",
    "@types/http-errors": "^1.8.1",
    "@types/jest": "^26.0.24",
    "@types/jsonwebtoken": "^8.5.6",
    "@types/jwk-to-pem": "^2.0.1",
    "@types/node-fetch": "^2.5.12",
    "@types/node-forge": "^0.10.8",
    "@typescript-eslint/eslint-plugin": "^5.8.1",
    "@typescript-eslint/parser": "^5.8.1",
    "amazon-cognito-identity-js": "^4.6.3",
    "aws-sdk": "^2.1052.0",
    "eslint": "^8.6.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-jest": "^25.3.4",
    "eslint-plugin-jsdoc": "^37.5.1",
    "eslint-plugin-prefer-arrow": "^1.2.3",
    "jest": "^26.6.3",
    "jest-create-mock-instance": "^2.0.0",
    "jsonc-parser": "^3.0.0",
    "openapi3-ts": "^2.0.1",
    "punycode": "^2.1.1",
    "rxjs": "^7.4.0",
    "source-map-support": "^0.5.21",
    "ts-jest": "^26.5.6",
    "ts-node": "^10.4.0",
    "typescript": "4.5.x",
    "yaml": "^1.10.2"
  }
}
f
I see. Can you try running
npx sst add-cdk aws-cdk-lib
? That will add
aws-cdk-lib
to your
package.json
. And that should fix this.
To add some context, when bundling the CDK code, all dependencies in
package.json
are set as
external
, so they shouldn’t be transpiled, so
__dirname
will point to the right spot.
a
Okay, manually adding
Copy code
"aws-cdk-lib": "2.7.0",
t
do you think we should hardcode aws-cdk-lib in that build?
f
yeah, agreed! Putting it in.
@Adam Fanello if u can confirm that resolves this issue.
a
Hmm. Built successful, output "Run npx sst deploy to deploy to AWS." and froze there. 😕
Okay, reset my shell environment and worked now. 👍
f
Alright, setting
aws-cdk-lib
as external by default. Will release this later today https://github.com/serverless-stack/serverless-stack/pull/1298
Thanks @Adam Fanello!