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

chore: Make helpers take one, not multiple Lambda functions (3/x) #336

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lym953
Copy link
Contributor

@lym953 lym953 commented Nov 20, 2024

Context of this PR series

The end goal of this series of PRs is to abort the instrumentation of a Lambda function if its runtime is not supported, while still instrument other Lambda functions. More in #314

However, this behavior is hard to implement under the current code structure:

public addLambdaFunctions() {
  grantReadLambdas(lambdas);
  applyLayers(lambdas);
  applyExtensionLayer(lambdas);
  ...
}

If one of the steps skips a Lambda function, it's hard for the subsequent steps to know this and thus skip the Lambda function.

Therefore, at the end of day, I'm going to change the code structure to:

public addLambdaFunctions() {
  for (lambda : lambdas) {
    addLambdaFunction(lambda);
  }
}

public addLambdaFunction() {
  if (!grantReadLambda(lambda)) {
    return;
  }

  if (!applyLayers(lambda)) {
    return;
  }
  ...
}

to make it possible to implement this behavior.

What does this PR do?

This PR makes these helper functions to take a single Lambda function instead of multiple ones:

  • applyExtensionLayer()
  • redirectHandlers()

It's not supposed to change code behavior.

I'll handle other helper functions in separate PRs, to keep each PR small and easy to review.

Testing Guidelines

Run snapshot tests: aws-vault exec sso-serverless-sandbox-account-admin -- scripts/run_integration_tests.sh to ensure the generated CloudFormation template for the test stacks are not changed.

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog

@lym953 lym953 requested a review from a team as a code owner November 20, 2024 20:42
});
const extensionLayerArn = getExtensionLayerArn(region, extensionLayerVersion, isARM, accountId);
log.debug(`Using extension layer: ${extensionLayerArn}`);
addLayer(extensionLayerArn, true, scope, lam, runtime);
return errors;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value errors is unused, so no need to worry about how this affects caller code.

Base automatically changed from yiming.luo/fix-nodejs-latest-2 to main November 21, 2024 19:14
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

Successfully merging this pull request may close these issues.

1 participant