Skip to content

Instantly share code, notes, and snippets.

@skierkowski
Created January 29, 2019 00:07
Show Gist options
  • Save skierkowski/eb7a43ba6e18d39e5773efb17abb178f to your computer and use it in GitHub Desktop.
Save skierkowski/eb7a43ba6e18d39e5773efb17abb178f to your computer and use it in GitHub Desktop.
Serverless Framework Enterprise Safeguard Policies
const { fromPairs } = require('lodash')
module.exports = function requireFunctionDescription(policy, service, options) {
const {
declaration: { functions },
provider: { naming },
compiled: {
'cloudformation-template-update-stack.json': { Resources }
}
} = service
const logicalFuncNamesToConfigFuncName = fromPairs(
Object.keys(functions || {}).map((funcName) => [naming.getLambdaLogicalId(funcName), funcName])
)
for (const [funcName, { Properties, Type}] of Object.entries(Resources)) {
if (Type !== 'AWS::Lambda::Function') {
continue
}
if (!Properties.Description) {
const configFuncName = logicalFuncNamesToConfigFuncName[funcName] || funcName
policy.warn (
`Description on function '${configFuncName}' is missing`
)
}
}
policy.approve()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment