Hi. I'm trying to use the `Script` construct to up...
# help
i
Hi. I'm trying to use the
Script
construct to upload some assets to a bucket. It's working, but the rollback feature isn't working as expected - when the function fails, it retries once and then nothing happens. The stack never finishes deploying, or becomes marked as a failed deploy (it's been about 50 minutes at time of writing). I can see my function code is working as expected - in the code snippet below, "2" is logged. Does anyone have any idea what else could be wrong?
Copy code
import * as debug from "../debug";
import { Handler } from "aws-lambda";

type Script<TParams = Record<string, never>, TResult = unknown> = Handler<{ params: TParams }, TResult>;

const aspect = <TParams>(lambda: Script<TParams>): typeof lambda => {
  return async (event, context, callback) => {
    debug.init(event);
    try {
      const res = await lambda(event, context, callback);
      return res;
    } catch (error) {
      console.log("1");
      debug.flush(error);
      console.log("2");
      throw error;
    }
  };
};

export default aspect;
f
Hi @Ivo Evans-Storrie, I think this could be a bug that
Script
is not handling Lambda errors correctly, and causing CloudFormation deploy to timeout.
Can I see how you are defining the
Script
construct?
i
Yeah sure,
Copy code
const deployExperiences = new sst.Function(this, "bundeSidebarFunction", {
      timeout: 900,
      handler: "resources/scripts/uploadExperiences/index.default",
      enableLiveDev: false,
      functionName: `bundle-experiences-${scope.stage}`,
      permissions: [assets, "cloudfront"],
      bundle: {
        minify: false,
        format: "esm",
        copyFiles: [
          {
            from: path.join(root, "experiences", "tr-kit", "public"),
            to: "experiences/booking",
          },
          { from: path.join(root, "frontend", "svelte-components", "package-js"), to: "experiences" },
        ],
      },
    });

    this.script = new sst.Script(this, "deployExperiences", {
      onCreate: deployExperiences,
      onUpdate: deployExperiences,
      params: {
        bucket: assets.bucketName,
        cloudfrontDistributionId: cloudfront.distributionId,
        apiUrl,
      },
    });
assets
here is an instance of
sst.Bucket
🙂
Oh and another thing that might be relevant is that all the params to the function are passed into this stack as props