diff --git a/src/guardian/index.js b/src/guardian/index.js index 944e659c..58740a0d 100644 --- a/src/guardian/index.js +++ b/src/guardian/index.js @@ -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, @@ -43,6 +44,7 @@ class GuardianCI { NoMaximumMemory, NoIdenticalCode, NoSharedRoles, + UseArm, ]; this.failingChecks = []; diff --git a/src/guardian/rules/best_practices/use-arm/index.js b/src/guardian/rules/best_practices/use-arm/index.js new file mode 100644 index 00000000..eecc89ee --- /dev/null +++ b/src/guardian/rules/best_practices/use-arm/index.js @@ -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; diff --git a/src/guardian/rules/best_practices/use-arm/use-arm.MD b/src/guardian/rules/best_practices/use-arm/use-arm.MD new file mode 100644 index 00000000..3dd47a5d --- /dev/null +++ b/src/guardian/rules/best_practices/use-arm/use-arm.MD @@ -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)