How to use yaml-cfn - 5 common examples

To help you get started, we’ve selected a few yaml-cfn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alukach / aws-sam-typescript-boilerplate / webpack.config.js View on Github external
const path = require('path');
const { readFileSync } = require('fs');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const { yamlParse } = require('yaml-cfn');

const conf = {
  prodMode: process.env.NODE_ENV === 'production',
  templatePath: './template.yaml',
};
const cfn = yamlParse(readFileSync(conf.templatePath));
const entries = Object.values(cfn.Resources)
  // Find nodejs functions
  .filter(v => v.Type === 'AWS::Serverless::Function')
  .filter(v =>
    (v.Properties.Runtime && v.Properties.Runtime.startsWith('nodejs')) ||
    (!v.Properties.Runtime && cfn.Globals.Function.Runtime)
  )
  .map(v => ({
    // Isolate handler src filename
    handlerFile: v.Properties.Handler.split('.')[0],
    // Build handler dst path
    CodeUriDir: v.Properties.CodeUri.split('/').splice(2).join('/')
  }))
  .reduce(
    (entries, v) =>
      Object.assign(
github SnappyTutorials / aws-sam-webpack-plugin / src / index.ts View on Github external
private entryFor(projectKey: string, projectTemplate: string) {
    const samConfig = yamlParse(fs.readFileSync(projectTemplate).toString());

    const defaultRuntime = samConfig.Globals?.Function?.Runtime ?? null;
    const defaultHandler = samConfig.Globals?.Function?.Handler ?? null;
    const defaultCodeUri = samConfig.Globals?.Function?.CodeUri ?? null;

    // Loop through all of the resources
    for (const resourceKey in samConfig.Resources) {
      const resource = samConfig.Resources[resourceKey];

      // Find all of the functions
      if (resource.Type === "AWS::Serverless::Function") {
        const properties = resource.Properties;
        if (!properties) {
          throw new Error(`${resourceKey} is missing Properties`);
        }
        // Check the runtime is supported
github SnappyTutorials / aws-sam-webpack-plugin / src / index.ts View on Github external
compiler.hooks.afterEmit.tap("SamPlugin", (compilation: any) => {
      if (this.samConfigs && this.launchConfig) {
        for (const samConfig of this.samConfigs) {
          fs.writeFileSync(`${samConfig.buildRoot}/template.yaml`, yamlDump(samConfig.samConfig));
        }
        if (this.options.vscodeDebug) {
          if (!fs.existsSync(".vscode")) {
            fs.mkdirSync(".vscode");
          }
          fs.writeFileSync(".vscode/launch.json", JSON.stringify(this.launchConfig));
        }
      } else {
        console.log("It looks like SamPlugin.entry() was not called");
      }
    });
  }
github gristlabs / aws-lambda-upload / lib / main.ts View on Github external
function parseTemplate(text: string, ext: string): any {
  try { return JSON.parse(text); } catch (e1) {
    if (ext === "json") {
      throw new Error(`Unable to parse JSON template: ${e1}`);
    }
    try { return yamlParse(text); } catch (e2) {
      throw new Error(`Unable to parse YAML template: ${e2}`);
    }
  }
}

yaml-cfn

Parser and schema for CloudFormation YAML template tags.

Apache-2.0
Latest version published 1 year ago

Package Health Score

47 / 100
Full package analysis

Popular yaml-cfn functions