sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.12k stars 136 forks source link

How to ensure specific files and directories are Included and accessible in function package? #294

Closed jesus-villagroup closed 2 months ago

jesus-villagroup commented 2 months ago

Hi,

I am working on a project to conduct automatic audits on providers and need to run tests programmatically in AWS Lambda using SST version 0.0.296. I'm trying to include an entire directory (src/tests) and a specific file (src/playwright.config.ts) in my function deployment package. My current configuration is as follows:

/// <reference path="./.sst/platform/config.d.ts" />

export default $config({
  app(input) {
    return {
      name: "watcher",
      removal: input?.stage === "production" ? "retain" : "remove",
      home: "aws",
    };
  },
  async run() {
    const helloWorldApp = new sst.aws.Function("WatcherHelloWorld", {
      handler: "src/functions/hello-world.handler",
      url: true,
      copyFiles: [
        { from: 'src/tests' },
        { from: 'src/playwright.config.ts' }
      ]
    });

    return {
      url: helloWorldApp.url
    }
  },
});

The function deploys without errors and the files are included in the deployment zip. However, when I execute ls -la using child_process inside the function, it shows that the src folder only contains the lambda handler file and not the copied files. How can I make sure these files are properly accessible and listed for execution by my code in Lambda?

jesus-villagroup commented 2 months ago

I have been analyzing how SST handles file deployment and noticed something intriguing. After running sst dev and deploying on AWS, the copied files are indeed present in the code.zip stored in .sst/artifacts/WatcherHelloWorld.

Captura de pantalla 2024-04-23 a la(s) 12 38 47 p m

However, once I visit the SST-provided endpoint and the deployment completes without errors, the original zip disappears and is replaced by a folder containing a symbolic link to node_modules and the src/functions/hello-world folder only housing index.mjs and its .mjs.map.

Captura de pantalla 2024-04-23 a la(s) 1 17 03 p m

The copied files are missing, which explains why my code cannot detect these files.

I will continue investigating this issue.