Skip to content

Commit

Permalink
yaml dump fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ljacobsson committed Oct 11, 2020
1 parent e515658 commit e62c12c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mhlabs/evb-cli",
"version": "1.1.14",
"version": "1.1.15",
"description": "A package for building EventBridge/CloudWatch Events patterns",
"main": "index.js",
"scripts": {
Expand Down
57 changes: 36 additions & 21 deletions src/template-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,20 @@ async function extractSamDefinition() {

const extractEvent = await inputUtil.selectFrom(
events,
"Select SAM event to extract"
"Select SAM event to extract",
true
);

delete template.Resources[extractEvent.function].Properties.Events[extractEvent.event];
delete template.Resources[extractEvent.function].Properties.Events[
extractEvent.event
];

if (
Object.keys(template.Resources[extractEvent.function].Properties.Events)
.length === 0
) {
delete template.Resources[extractEvent.function].Properties.Events;
}

let suggestion = `${extractEvent.event}Rule`;
if (template.Resources[suggestion]) {
Expand All @@ -151,29 +160,35 @@ async function extractSamDefinition() {
EventBusName: extractEvent.config.EventBusName || "default",
EventPattern: extractEvent.config.Pattern,
State: "ENABLED",
Targets: [{
Arn: { "Fn::GetAtt": [extractEvent.function, "Arn"] },
Id: suggestion,
Input: extractEvent.config.Input,
InputPath: extractEvent.config.InputPath
}],
Targets: [
{
Arn: { "Fn::GetAtt": [extractEvent.function, "Arn"] },
Id: suggestion,
},
],
},
};

if (extractEvent.config.Input) {
template.Resources[resourceName].Properties.Targets[0].Input =
extractEvent.config.Input;
}
if (extractEvent.config.InputPath) {
template.Resources[resourceName].Properties.Targets[0].InputPath =
extractEvent.config.InputPath;
}
template.Resources[`${resourceName}Permission`] = {
Type: "AWS::Lambda::Permission",
Properties: {
FunctionName: {
Ref: extractEvent.function
},
Action: "lambda:InvokeFunction",
Principal: "events.amazonaws.com",
SourceArn: {
"Fn::GetAtt": [
suggestion,
"Arn"
]
}
}
Properties: {
FunctionName: {
Ref: extractEvent.function,
},
Action: "lambda:InvokeFunction",
Principal: "events.amazonaws.com",
SourceArn: {
"Fn::GetAtt": [suggestion, "Arn"],
},
},
};

saveTemplate();
Expand Down

0 comments on commit e62c12c

Please sign in to comment.