Skip to content

Commit ee7ba21

Browse files
committed
Add Use Arm Architecture Rule
1 parent 6c55c87 commit ee7ba21

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/guardian/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import NoMaximumTimeout from "./rules/best_practices/no-max-timeout";
77
import NoMaximumMemory from "./rules/best_practices/no-max-memory";
88
import NoIdenticalCode from "./rules/best_practices/no-identical-code";
99
import NoSharedRoles from "./rules/best_practices/no-shared-roles";
10+
import UseArm from "./rules/best_practices/use-arm";
1011
import {
1112
getAWSCredentials,
1213
getStackResources,
@@ -43,6 +44,7 @@ class GuardianCI {
4344
NoMaximumMemory,
4445
NoIdenticalCode,
4546
NoSharedRoles,
47+
UseArm,
4648
];
4749
this.failingChecks = [];
4850

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
class UseArm {
2+
constructor(AWS, stackName, stackFunctions, SLS) {
3+
this.name = "use-arm";
4+
this.AWS = AWS;
5+
this.stackName = stackName;
6+
this.stackFunctions = stackFunctions;
7+
this.result = false;
8+
this.failingResources = [];
9+
this.armArchitecture = "arm64";
10+
this.SLS = SLS;
11+
this.failureMessage =
12+
"The following functions do not use an arm64 architecture.";
13+
this.rulePage =
14+
"See (https://theodo-uk.github.io/sls-dev-tools/docs/no-default-memory) for impact and how to to resolve.";
15+
}
16+
17+
hasArmArchitecture(lambdaFunction) {
18+
return lambdaFunction.Architectures[0] === this.armArchitecture;
19+
}
20+
21+
async run() {
22+
console.log(this.stackFunctions);
23+
try {
24+
const notArmFunctions = this.stackFunctions.reduce(
25+
(acc, current) =>
26+
this.hasArmArchitecture(current) ? acc : [...acc, current],
27+
[]
28+
);
29+
30+
this.failingResources = notArmFunctions.map((lambda) => ({
31+
arn: lambda.FunctionArn,
32+
architecture: lambda.Architectures[0],
33+
}));
34+
35+
if (notArmFunctions.length > 0) {
36+
this.result = false;
37+
} else {
38+
this.result = true;
39+
}
40+
} catch (e) {
41+
console.error(e);
42+
this.result = false;
43+
}
44+
return this.result;
45+
}
46+
}
47+
48+
export default UseArm;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# All functions have an arm64 architecture
2+
3+
Lambdas Functions default architecture is x86_64 but should be configure to arm64.
4+
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.
5+
6+
---
7+
8+
## Suggested Actions:
9+
10+
- 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 commit comments

Comments
 (0)