Hi there! I'm getting a funny error while running ...
# help
f
Hi there! I'm getting a funny error while running
sst build
and I'm wondering if you could help?
Copy code
Error: Cannot find asset at /Users/franco/Remi/Repository/remi/.build/lib/runtime
    at new AssetStaging (/Users/franco/Remi/Repository/remi/node_modules/aws-cdk-lib/core/lib/asset-staging.ts:109:13)
    at new Asset (/Users/franco/Remi/Repository/remi/node_modules/aws-cdk-lib/aws-s3-assets/lib/asset.ts:72:21)
    at AssetCode.bind (/Users/franco/Remi/Repository/remi/node_modules/aws-cdk-lib/aws-lambda/lib/code.ts:180:20)
    at new Function2 (/Users/franco/Remi/Repository/remi/node_modules/aws-cdk-lib/aws-lambda/lib/function.ts:350:29)
    at SingletonFunction.ensureLambda (/Users/franco/Remi/Repository/remi/node_modules/aws-cdk-lib/aws-lambda/lib/singleton-lambda.ts:119:12)
    at new SingletonFunction (/Users/franco/Remi/Repository/remi/node_modules/aws-cdk-lib/aws-lambda/lib/singleton-lambda.ts:41:32)
    at new AwsCustomResource2 (/Users/franco/Remi/Repository/remi/node_modules/aws-cdk-lib/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts:190:22)
    at new DBMigrationStack (/Users/franco/Remi/Repository/remi/infra/src/DBMigrationStack.ts:21:29)
    at Object.main (/Users/franco/Remi/Repository/remi/infra/src/index.ts:16:32)
    at Object.<anonymous> (/Users/franco/Remi/Repository/remi/.build/run.js:94:16)
I see from other questions that this is usually due missing cdk packages but I'm a bit lost on what to add here since it's us the ones creating the custom resource directly. Also bumped to the last SST version to use CDK2 without success. Any ideas? Here's the snippet:
Copy code
import * as sst from "@serverless-stack/resources";
import * as ec2 from "aws-cdk-lib/aws-ec2";
import * as cr from "aws-cdk-lib/custom-resources";
import { StringParameter } from "aws-cdk-lib/aws-ssm";

type NetworkDetails = {
    vpc: ec2.IVpc;
    securityGroup: ec2.ISecurityGroup;
};

export default class DBMigrationStack extends sst.Stack {
    constructor(scope: <http://sst.App|sst.App>, id: string, networkDetails: NetworkDetails, props?: sst.StackProps) {
        super(scope, id, props);

        const DB_NAME = StringParameter.valueForStringParameter(this, "/REMI/DB_NAME");
        const DB_USER = StringParameter.valueForStringParameter(this, "/REMI/DB_USER");
        const DB_HOST = StringParameter.valueForStringParameter(this, `/REMI/DB_HOST/${scope.stage}`);
        const DB_PORT = StringParameter.valueForStringParameter(this, "/REMI/DB_PORT");

        // Custom resource is needed here since we cannot fetch secure strings from ssm otherwise
        const DB_PASSWORD = new cr.AwsCustomResource(this, "GetParameter", {
            onUpdate: {
                // will also be called for a CREATE event
                service: "SSM",
                action: "getParameter",
                parameters: {
                    Name: "/REMI/DB_PASSWORD",
                    WithDecryption: true,
                },
                // Update physical id to always fetch the latest version
                physicalResourceId: cr.PhysicalResourceId.of(Date.now().toString()),
            },
            policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
                resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
            }),
        });

        new sst.Script(this, "Script", {
            onCreate: "core/config/database/migrator.main",
            onUpdate: "core/config/database/migrator.main",
            params: {
                DB_NAME,
                DB_USER,
                DB_PASSWORD: DB_PASSWORD.getResponseField("Parameter.Value"),
                DB_HOST,
                DB_PORT,
            },
            defaultFunctionProps: {
                vpc: networkDetails.vpc,
                securityGroups: [networkDetails.securityGroup],
                bundle: {
                    copyFiles: [
                        {
                            from: "core/config/database/migrations",
                            to: "core/config/database/migrations",
                        },
                    ],
                    nodeModules: ["@mikro-orm/core", "@mikro-orm/migrations", "@mikro-orm/postgresql", "knex", "pg"],
                    externalModules: [
                        "@mikro-orm/sqlite",
                        "@mikro-orm/mariadb",
                        "@mikro-orm/mysql",
                        "@mikro-orm/mongodb",
                        "pg-native",
                        "mysql",
                        "sqlite3",
                    ],
                },
            },
        });
    }
}
also package.json
Copy code
"dependencies": {
        "@serverless-stack/cli": "0.59.1",
        "@serverless-stack/resources": "0.59.1",
        "@serverless-stack/static-site-env": "^0.59.1"
    },
f
Hey @Franco Gotusso, are you still having the issue? Can you try wiping out ur
node_modules
folder and the npm/yarn lock file, and give it a try again?
f
morning! I gave it a try and it's still the same unfortunately
f
@Franco Gotusso sorry for the late followup. Did you manage to get around the issue? Do you have
aws-cdk-lib
listed under
dependencies
?
If you, can you try running
npx sst add-cdk aws-cdk-lib
and then give this a try again?