Skip to content

Instantly share code, notes, and snippets.

@breenie
Last active January 26, 2024 15:19
Show Gist options
  • Save breenie/51073284f5c10811bcdf48b81813f4c3 to your computer and use it in GitHub Desktop.
Save breenie/51073284f5c10811bcdf48b81813f4c3 to your computer and use it in GitHub Desktop.
Convert output from cloudformation get-template-summary into an importable file

How to run the script

$ aws cloudformation get-template-summary --template-body file://template.yml > /path/to/summary.json
$ node index.js < /path/to/summary.json > /path/to/resources.json

Fill in the missing values in your the output file and import it.

$ aws cloudformation create-change-set \
  --stack-name stack-name \
  --change-set-name import \
  --change-set-type IMPORT \
  --resources-to-import file:///path/to/resources.json \
  --template-body file:///path/to/template.yml
let inputData = "";
process.stdin.setEncoding("utf-8");
process.stdin.on("data", (chunk) => {
inputData += chunk;
});
process.stdin.on("end", () => {
const { ResourceIdentifierSummaries } = JSON.parse(inputData);
const output = ResourceIdentifierSummaries.reduce(
(acc, { ResourceType, LogicalResourceIds, ResourceIdentifiers }) => {
acc.push(
...LogicalResourceIds.reduce((a, LogicalResourceId) => {
a.push({
ResourceType,
LogicalResourceId,
ResourceIdentifier: ResourceIdentifiers[0]
.split(",")
.map((s) => s.trim())
.reduce((a, k) => {
a[k] = "";
return a;
}, {})
});
return a;
}, [])
);
return acc;
},
[]
);
console.log(JSON.stringify(output, null, 2));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment