-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added CloudFormation template extratctor * Added `yaml-cfn`package * Added `app.ts` * Added CloudFormation extractor tests * Added filter tests * fix: Added fixed * Linted files * update implementation * fix typo
- Loading branch information
1 parent
44ecbff
commit 52ea5d9
Showing
20 changed files
with
2,293 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,114 @@ | ||
|
||
############### - 7 - ################ | ||
|
||
--- SQSs of 7 --- | ||
[ | ||
{ | ||
"LogicalId": "jobsDlqD18CF374", | ||
"Properties": { | ||
"MessageRetentionPeriod": 1209600, | ||
"QueueName": "aws-node-sqs-worker-project-dev-jobs-dlq" | ||
} | ||
}, | ||
{ | ||
"LogicalId": "jobsQueueCEDBAE3E", | ||
"Properties": { | ||
"DelaySeconds": 60, | ||
"QueueName": "aws-node-sqs-worker-project-dev-jobs", | ||
"RedrivePolicy": { | ||
"deadLetterTargetArn": { | ||
"Fn::GetAtt": [ | ||
"jobsDlqD18CF374", | ||
"Arn" | ||
] | ||
}, | ||
"maxReceiveCount": 3 | ||
}, | ||
"VisibilityTimeout": 69 | ||
} | ||
} | ||
] | ||
--- Lambdas of 7 --- | ||
[ | ||
{ | ||
"LogicalId": "ProducerLambdaFunction", | ||
"Properties": { | ||
"Code": { | ||
"S3Bucket": { | ||
"Ref": "ServerlessDeploymentBucket" | ||
}, | ||
"S3Key": "serverless/aws-node-sqs-worker-project/dev/1705833879496-2024-01-21T10:44:39.496Z/aws-node-sqs-worker-project.zip" | ||
}, | ||
"Handler": "index.producer", | ||
"Runtime": "nodejs18.x", | ||
"FunctionName": "aws-node-sqs-worker-project-dev-producer", | ||
"MemorySize": 1024, | ||
"Timeout": 6, | ||
"Environment": { | ||
"Variables": { | ||
"QUEUE_URL": { | ||
"Ref": "jobsQueueCEDBAE3E" | ||
} | ||
} | ||
}, | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"IamRoleLambdaExecution", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"LogicalId": "JobsWorkerLambdaFunction", | ||
"Properties": { | ||
"Code": { | ||
"S3Bucket": { | ||
"Ref": "ServerlessDeploymentBucket" | ||
}, | ||
"S3Key": "serverless/aws-node-sqs-worker-project/dev/1705833879496-2024-01-21T10:44:39.496Z/aws-node-sqs-worker-project.zip" | ||
}, | ||
"Handler": "index.consumer", | ||
"Runtime": "nodejs18.x", | ||
"FunctionName": "aws-node-sqs-worker-project-dev-jobsWorker", | ||
"MemorySize": 1024, | ||
"Timeout": 6, | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"IamRoleLambdaExecution", | ||
"Arn" | ||
] | ||
}, | ||
"ReservedConcurrentExecutions": 200 | ||
} | ||
} | ||
] | ||
--- EventSourceMappings of 7 --- | ||
[ | ||
{ | ||
"LogicalId": "JobsWorkerEventSourceMappingSQSJobsQueueCEDBAE3E", | ||
"Properties": { | ||
"BatchSize": 5, | ||
"MaximumBatchingWindowInSeconds": 33, | ||
"EventSourceArn": { | ||
"Fn::GetAtt": [ | ||
"jobsQueueCEDBAE3E", | ||
"Arn" | ||
] | ||
}, | ||
"FunctionName": { | ||
"Fn::GetAtt": [ | ||
"JobsWorkerLambdaFunction", | ||
"Arn" | ||
] | ||
}, | ||
"Enabled": true, | ||
"FunctionResponseTypes": [ | ||
"ReportBatchItemFailures" | ||
], | ||
"ScalingConfig": { | ||
"MaximumConcurrency": 1000 | ||
} | ||
} | ||
} | ||
] |
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,82 @@ | ||
import { Lambda, SQS } from "cloudform-types"; | ||
import { extract } from "./src/helpers/cf-extractor"; | ||
import { filter } from "./src/helpers/filter"; | ||
import { Worker } from "./src/worker"; | ||
|
||
const fs = require("fs"); | ||
|
||
const run = () => { | ||
const workers: Worker[] = []; | ||
for (let index = 1; index <= 7; index++) { | ||
const path = `./mock/template${index}.json`; | ||
const template = JSON.parse(fs.readFileSync(path)); | ||
const filtered = filter(template); | ||
filtered.forEach( | ||
( | ||
options: Record< | ||
string, | ||
| Partial<SQS.Queue> | ||
| Partial<Lambda.Function> | ||
| Partial<Lambda.EventSourceMapping> | ||
>, | ||
) => { | ||
const worker = new Worker({ | ||
id: `${index}_worker-${Date.now()}`, | ||
// @ts-ignore | ||
lambda: options.lambda, | ||
// @ts-ignore | ||
integration: options.integration, | ||
// @ts-ignore | ||
sqs: options.sqs, | ||
}); | ||
workers.push(worker); | ||
}, | ||
); | ||
} | ||
workers.forEach((worker: Worker) => { | ||
worker.analyze(); | ||
}); | ||
}; | ||
|
||
const run1 = () => { | ||
fs.writeFileSync("b.json", ""); | ||
for (let index = 7; index <= 7; index++) { | ||
const path = `./mock/template${index}.json`; | ||
const template = JSON.parse(fs.readFileSync(path)); | ||
const options = filter(template); | ||
if (options.length > 0) { | ||
fs.appendFileSync("b.json", `\n --- Options of ${index} --- \n`); | ||
fs.appendFileSync("b.json", JSON.stringify(options, null, 2)); | ||
} | ||
} | ||
}; | ||
const run2 = () => { | ||
fs.writeFileSync("a.json", ""); | ||
for (let index = 7; index <= 7; index++) { | ||
const path = `./mock/template${index}.json`; | ||
const template = JSON.parse(fs.readFileSync(path)); | ||
const sqs = extract(template, "AWS::SQS::Queue"); | ||
const lambdas = extract(template, "AWS::Lambda::Function"); | ||
const mappings = extract(template, "AWS::Lambda::EventSourceMapping"); | ||
if (sqs.length > 0 && lambdas.length > 0 && mappings.length > 0) { | ||
fs.appendFileSync( | ||
"a.json", | ||
`\n############### - ${index} - ################\n`, | ||
); | ||
fs.appendFileSync("a.json", `\n --- SQSs of ${index} --- \n`); | ||
fs.appendFileSync("a.json", JSON.stringify(sqs, null, 2)); | ||
fs.appendFileSync("a.json", `\n --- Lambdas of ${index} --- \n`); | ||
fs.appendFileSync("a.json", JSON.stringify(lambdas, null, 2)); | ||
fs.appendFileSync( | ||
"a.json", | ||
`\n --- EventSourceMappings of ${index} --- \n`, | ||
); | ||
fs.appendFileSync("a.json", JSON.stringify(mappings, null, 2)); | ||
} | ||
} | ||
console.log("Done"); | ||
}; | ||
|
||
run(); | ||
run1(); | ||
run2(); |
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,72 @@ | ||
|
||
--- Options of 7 --- | ||
[ | ||
{ | ||
"integration": { | ||
"LogicalId": "JobsWorkerEventSourceMappingSQSJobsQueueCEDBAE3E", | ||
"Properties": { | ||
"BatchSize": 5, | ||
"MaximumBatchingWindowInSeconds": 33, | ||
"EventSourceArn": { | ||
"Fn::GetAtt": [ | ||
"jobsQueueCEDBAE3E", | ||
"Arn" | ||
] | ||
}, | ||
"FunctionName": { | ||
"Fn::GetAtt": [ | ||
"JobsWorkerLambdaFunction", | ||
"Arn" | ||
] | ||
}, | ||
"Enabled": true, | ||
"FunctionResponseTypes": [ | ||
"ReportBatchItemFailures" | ||
], | ||
"ScalingConfig": { | ||
"MaximumConcurrency": 1000 | ||
} | ||
} | ||
}, | ||
"lambda": { | ||
"LogicalId": "JobsWorkerLambdaFunction", | ||
"Properties": { | ||
"Code": { | ||
"S3Bucket": { | ||
"Ref": "ServerlessDeploymentBucket" | ||
}, | ||
"S3Key": "serverless/aws-node-sqs-worker-project/dev/1705833879496-2024-01-21T10:44:39.496Z/aws-node-sqs-worker-project.zip" | ||
}, | ||
"Handler": "index.consumer", | ||
"Runtime": "nodejs18.x", | ||
"FunctionName": "aws-node-sqs-worker-project-dev-jobsWorker", | ||
"MemorySize": 1024, | ||
"Timeout": 6, | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"IamRoleLambdaExecution", | ||
"Arn" | ||
] | ||
}, | ||
"ReservedConcurrentExecutions": 200 | ||
} | ||
}, | ||
"sqs": { | ||
"LogicalId": "jobsQueueCEDBAE3E", | ||
"Properties": { | ||
"DelaySeconds": 60, | ||
"QueueName": "aws-node-sqs-worker-project-dev-jobs", | ||
"RedrivePolicy": { | ||
"deadLetterTargetArn": { | ||
"Fn::GetAtt": [ | ||
"jobsDlqD18CF374", | ||
"Arn" | ||
] | ||
}, | ||
"maxReceiveCount": 3 | ||
}, | ||
"VisibilityTimeout": 69 | ||
} | ||
} | ||
} | ||
] |
Oops, something went wrong.