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

feature(rules): add arm architecture rule #695

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sls-dev-tools": "./lib/index.js"
},
"dependencies": {
"aws-sdk": "^2.655.0",
"aws-sdk": "^2.1124.0",
"blessed": "^0.1.81",
"blessed-contrib": "^4.8.17",
"chalk": "^4.0.0",
Expand Down
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)
Loading