EndemolShineGroup/serverless-test-utils

View on GitHub
src/aws/cloudFormation/listStackOutputs.ts

Summary

Maintainability
A
0 mins
Test Coverage
import AWS from 'aws-sdk';

/**
 * This functions lists any stack outputs
 * @param stackName
 */
export default async (stackName: string) => {
  const cloudformation = new AWS.CloudFormation();

  const response = await cloudformation
    .describeStacks({ StackName: stackName })
    .promise();

  if (!response.Stacks) {
    throw new Error(`No stacks found`);
  }

  const retrievedStack = response.Stacks.find((stack) => {
    return stack.StackName === stackName;
  });

  if (!retrievedStack) {
    throw new Error(`No stack found with name ${stackName}`);
  }

  return retrievedStack.Outputs;
};