Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from ap2020/feature/reorganize-resources
- Loading branch information
Showing
13 changed files
with
916 additions
and
443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const tables = async ({ resolveConfigurationProperty }) => await resolveConfigurationProperty(['custom', 'dynamodbConfig', 'tableName']); | ||
module.exports.tables = tables; | ||
|
||
const fullnames = async (sls) => Object.values(await tables(sls)); | ||
module.exports.fullnames = fullnames; | ||
|
||
const arns = async (sls) => (await fullnames(sls)).map(table => `arn:aws:dynamodb:\${self:provider.region}:\${self:custom.accountId}:table/${table}`); | ||
module.exports.arns = arns; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const calcFullname = func => `ap2020bot-\${self:custom.stage}-${func}`; | ||
module.exports.calcFullname = calcFullname; | ||
|
||
const calcArnFromFullName = func => `arn:aws:lambda:\${self:provider.region}:\${self:custom.accountId}:function:${func}`; | ||
module.exports.calcArnFromFullName = calcArnFromFullName; | ||
|
||
const calcArnFromShortName = func => calcArnFromFullName(calcFullname(func)); | ||
module.exports.calcArnFromShortName = calcArnFromShortName; | ||
|
||
const functions = async ({ resolveConfigurationProperty }) => { | ||
return await resolveConfigurationProperty(['functions']); | ||
} | ||
|
||
const shortnames = async (sls) => Object.keys(await functions(sls)); | ||
module.exports.shortnames = shortnames; | ||
|
||
const fullnames = async (sls) => (await shortnames(sls)).map(func => calcFullname(func)); | ||
module.exports.fullnames = fullnames; | ||
|
||
const arns = async (sls) => (await fullnames(sls)).map(func => calcArnFromFullName(func)); | ||
module.exports.arns = arns; | ||
|
||
const logGroupArns = async (sls) => (await fullnames(sls)).map(func => `arn:aws:logs:\${self:provider.region}:\${self:custom.accountId}:log-group:/aws/lambda/${func}:*`); | ||
module.exports.logGroupArns = logGroupArns; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const topics = async ({ resolveConfigurationProperty }) => await resolveConfigurationProperty(['custom', 'sns', 'topicName']); | ||
module.exports.topics = topics; | ||
|
||
const fullnames = async (sls) => Object.values(await topics(sls)); | ||
module.exports.fullnames = fullnames; | ||
|
||
const arns = async (sls) => (await fullnames(sls)).map(topic => `arn:aws:sns:\${self:provider.region}:\${self:custom.accountId}:${topic}`); | ||
module.exports.arns = arns; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const { STS } = require('aws-sdk'); | ||
const sts = new STS(); | ||
|
||
module.exports.accountId = async () => (await sts.getCallerIdentity().promise()).Account; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const {pascalCase} = require('change-case'); | ||
|
||
const { shortnames: getFuncShortnames, calcFullname } = require('../lib/functions'); | ||
|
||
const calcAlarmName = (funcShortname) => `ap2020bot-\${self:custom.stage}-error-${funcShortname}`; | ||
|
||
const createAlarm = (func) => ([ | ||
`${pascalCase(func)}ErrorAlarm`, | ||
{ | ||
"Type": "AWS::CloudWatch::Alarm", | ||
"Properties": { | ||
"AlarmName": calcAlarmName(func), | ||
"Namespace": "AWS/Lambda", | ||
"Dimensions": [ | ||
{ | ||
"Name": "FunctionName", | ||
"Value": calcFullname(func), | ||
} | ||
], | ||
"MetricName": "Errors", | ||
"ComparisonOperator": "GreaterThanOrEqualToThreshold", | ||
"Period": 60, | ||
"EvaluationPeriods": 1, | ||
"Statistic": "Maximum", | ||
"Threshold": 1, | ||
"AlarmActions": [ | ||
{ | ||
"Ref": "ErrorTopic" | ||
} | ||
] | ||
} | ||
}, | ||
]); | ||
|
||
const names = async (sls) => { | ||
const functions = await getFuncShortnames(sls); | ||
return functions.map(func => calcAlarmName(func)); | ||
}; | ||
module.exports.names = names; | ||
|
||
const arns = async (sls) => (await names(sls)).map(alarm => `arn:aws:cloudwatch:\${self:provider.region}:\${self:custom.accountId}:alarm:${alarm}`); | ||
module.exports.arns = arns; | ||
|
||
const cfn = async (sls) => { | ||
const functions = await getFuncShortnames(sls); | ||
return { | ||
"Resources": Object.fromEntries(functions.map(func => createAlarm(func))), | ||
}; | ||
}; | ||
module.exports.cfn = cfn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Resources: | ||
Ap2020BotAdminGroup: | ||
Type: AWS::IAM::Group | ||
Properties: | ||
GroupName: 'ap2020bot-admin-${self:custom.stage}' | ||
ManagedPolicyArns: | ||
- Ref: Ap2020DeployAdminAssumablePolicy |
Oops, something went wrong.