Skip to content

Commit

Permalink
Add Use Arm Architecture Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
gozineb committed Apr 29, 2022
1 parent 0d49c54 commit d7845a3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/guardian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import NoMaximumTimeout from "./rules/best_practices/no-max-timeout";
import NoMaximumMemory from "./rules/best_practices/no-max-memory";
import NoIdenticalCode from "./rules/best_practices/no-identical-code";
import NoSharedRoles from "./rules/best_practices/no-shared-roles";
import UseArm from "./rules/best_practices/use-arm";
import {
getAWSCredentials,
getStackResources,
Expand Down Expand Up @@ -43,6 +44,7 @@ class GuardianCI {
NoMaximumMemory,
NoIdenticalCode,
NoSharedRoles,
UseArm,
];
this.failingChecks = [];

Expand Down
48 changes: 48 additions & 0 deletions src/guardian/rules/best_practices/use-arm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class UseArm {
constructor(AWS, stackName, stackFunctions, SLS) {
this.name = "use-arm";
this.AWS = AWS;
this.stackName = stackName;
this.stackFunctions = stackFunctions;
this.result = false;
this.failingResources = [];
this.armArchitecture = "arm64";
this.SLS = SLS;
this.failureMessage =
"The following functions do not use an arm64 architecture.";
this.rulePage =
"See (https://theodo-uk.github.io/sls-dev-tools/docs/no-default-memory) for impact and how to to resolve.";
}

hasArmArchitecture(lambdaFunction) {
return lambdaFunction.Architectures[0] === this.armArchitecture;
}

async run() {
console.log(this.stackFunctions);
try {
const notArmFunctions = this.stackFunctions.reduce(
(acc, current) =>
this.hasArmArchitecture(current) ? acc : [...acc, current],
[]
);

this.failingResources = notArmFunctions.map((lambda) => ({
arn: lambda.FunctionArn,
architecture: lambda.Architectures[0],
}));

if (notArmFunctions.length > 0) {
this.result = false;
} else {
this.result = true;
}
} catch (e) {
console.error(e);
this.result = false;
}
return this.result;
}
}

export default UseArm;
10 changes: 10 additions & 0 deletions src/guardian/rules/best_practices/use-arm/use-arm.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# All functions have an arm64 architecture

Lambdas Functions default architecture is x86_64 but should be configure to arm64.
Lambda functions that use arm64 architecture (AWS Graviton2 processor) can achieve significantly better price and performance than the equivalent function running on x86_64 architecture.

---

## Suggested Actions:

- Look into your function in your Lambda service to find `Architectures` in the code tab Runtime Settings. [more information](https://docs.aws.amazon.com/lambda/latest/dg/foundation-arch.html#foundation-arch-adv)

0 comments on commit d7845a3

Please sign in to comment.