Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payload with variables do not work with AWS Lambda or Fargate #2476

Open
cbjogura opened this issue Feb 5, 2024 · 1 comment
Open

Payload with variables do not work with AWS Lambda or Fargate #2476

cbjogura opened this issue Feb 5, 2024 · 1 comment

Comments

@cbjogura
Copy link

cbjogura commented Feb 5, 2024

Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating it.
\\-->

Version info:

Artillery: 2.0.4
Node.js:   v18.16.0
OS:        darwin

Running this command:

artillery run:lambda --subnet-ids subnet-1,subnet-2 --security-group-ids sg-1 --region us-east-1 --count 1 -e dev src/api-load.yaml

I expected to see this happen (notice that the dev is resolved for the {{ $environment }}-credentials.csv & {{ $environment }}-srv-credential.csv:

NOTE: AWS Lambda support is experimental. Not all Artillery features work yet.
For details please see https://docs.art/aws-lambda

λ Creating AWS Lambda function...
- Bundling test data
  - api-load.yaml
  - processor.js
  - dev-credential.csv
  - dev-srv-credential.csv
  
  .
  .
  .

Instead, this happened:

NOTE: AWS Lambda support is experimental. Not all Artillery features work yet.
For details please see https://docs.art/aws-lambda

λ Creating AWS Lambda function...
- Bundling test data
  - api-load.yaml
  - processor.js
  - {{ $environment }}-credential.csv
  - {{ $environment }}-srv-credential.csv

Error: ENOENT: no such file or directory, copyfile '/Users/me/dev/src/{{ $environment }}-credential.csv' -> '/var/folders/pz/rkq06hx523x57556q_60z0880000gq/T/d-202415-47418-uyo2yf.y1xdl/{{ $environment }}-credential.csv'
    at Object.copyFileSync (node:fs:2894:3)
    at PlatformLambda.init (/Users/me/dev/node_modules/artillery/lib/platform/aws-lambda/index.js:171:10)
    at async Launcher.run (/Users/jme/dev/node_modules/artillery/lib/launch-platform.js:428:25) {
  errno: -2,
  syscall: 'copyfile',
  code: 'ENOENT',
  path: '/Users/me/dev/src/{{ $environment }}-credential.csv',
  dest: '/var/folders/pz/rkq06hx523x57556q_60z0880000gq/T/d-202415-47418-uyo2yf.y1xdl/{{ $environment }}-credential.csv'
}

Files being used:

config:
  payload:
    # path is relative to the location of the test script
    - path: ./{{ $environment }}-credential.csv  ### <--- $environment is sub for the `-e dev` on the CLI
      skipHeader: true
      fields:
        - frameworkServiceName
        - frameworkServicePassword
      order: sequence
    # path is relative to the location of the test script
    - path: ./{{ $environment }}-srv-credential.csv  ### <--- $environment is sub for the `-e dev` on the CLI
      skipHeader: true
      fields:
        - serviceName
        - servicePassword
      order: random

This works locally. But when trying to create the test bundle for Lambda or ECS.

The issue is in the createBom() functions (there are two one for Lambda and one for ECS) the current code is not resolving any types of variables that could be passed in from the CLI:

Current code:

async function createBOM(absoluteScriptPath, extraFiles, opts, callback) {
  A.waterfall(
    [
      A.constant(absoluteScriptPath),
      readScript,
      parseScript,
      (scriptData, next) => {
        return next(null, {
          opts: {
            scriptData,
            absoluteScriptPath
          },
          localFilePaths: [absoluteScriptPath],
          npmModules: []
        });
      },
      getPlugins,
      getCustomEngines,
      getCustomJsDependencies,
      getVariableDataFiles,
      // getFileUploadPluginFiles,
      getExtraFiles
      // expandDirectories
    ],

Possible fix:

async function createBOM(absoluteScriptPath, extraFiles, opts, callback) {
  A.waterfall(
    [
      A.constant(absoluteScriptPath),
      readScript,
      parseScript,
      // Potential Fix: ResolveConfig templates here (but requires the flags to propagate to this function)
      async (scriptData) => {
        return await resolveConfigTemplates(scriptData, opts);
      },
      (scriptData, next) => {
        return next(null, {
          opts: {
            scriptData,
            absoluteScriptPath
          },
          localFilePaths: [absoluteScriptPath],
          npmModules: []
        });
      },
      getPlugins,
      getCustomEngines,
      getCustomJsDependencies,
      getVariableDataFiles,
      // getFileUploadPluginFiles,
      getExtraFiles
      // expandDirectories
    ],

In the init() method to populate the opts variable:

    // populate the cliOptions into the `createBomOpts` for template resolution
    createBomOpts = { 
      ...createBomOpts,
      ...this.opts,
    };
    const bom = await promisify(createBOM)(
      entryPoint,
      extraFiles,
      createBomOpts
    );

Same pattern to fix would apply for the ECS version (done in the prepareManifest function)

Expected behavior:

Test bundle prepared... [11:37:24]
Test bundle contents:
┌───────────────────────────┬──────┬───────┐
│ Name                      │ Type │ Notes │
├───────────────────────────┼──────┼───────┤
│ api-load.yaml             │ file │       │
├───────────────────────────┼──────┤       │
│ processor.js              │ file │       │
├───────────────────────────┼──────┤       │
│ dev-credential.csv        │ file │       │
├───────────────────────────┼──────┤       │
│ dev-srv-credential.csv    │ file │       │
└───────────────────────────┴──────┴───────┘

Instead:

Test bundle prepared... [11:28:47]
Test bundle contents:
┌───────────────────────────────────────┬──────┬───────┐
│ Name                                  │ Type │ Notes │
├───────────────────────────────────────┼──────┼───────┤
│ api-load.yaml                         │ file │       │
├───────────────────────────────────────┼──────┤       │
│ processor.js                          │ file │       │
├───────────────────────────────────────┼──────┤       │
│ {{ $environment }}-credential.csv     │ file │       │
├───────────────────────────────────────┼──────┤       │
│ {{ $environment }}-srv-credential.csv │ file │       │
└───────────────────────────────────────┴──────┴───────┘
@prabhakaran-repos
Copy link

When can we expect this fix? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants