How to use serverless - 8 common examples

To help you get started, we’ve selected a few serverless 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 jacob-meacham / serverless-plugin-aws-resolvers / test / index.spec.js View on Github external
function createFakeServerless() {
    const sls = new Serverless()
    // Attach the plugin
    sls.pluginManager.addPlugin(ServerlessAWSResolvers)
    sls.init()
    return sls
  }
github jacob-meacham / serverless-plugin-deploy-environment / test / index.spec.js View on Github external
test('Skips credstash populate if requested', async t => {
  const sls = new Serverless()

  sls.service.custom = _.cloneDeep(CREDSTASH_CONFIG)

  const plugin = initServerlessPlugin(sls)
  plugin.options.credstash = 'false'

  await sls.variables.populateService()
  t.is(sls.service.custom.test.a, 'credstash:testCredential') // eslint-disable-line
})
github danilop / ServerlessByDesign / src / engines / servfrmwk.js View on Github external
var node = model.nodes[id];
    renderingRules[node.type].resource(status, node);
  }

  console.log(template); // Still in JSON
  console.log(JSON.stringify(template, null, 4)); // JSON -> text

  for (var r in template.Resources) {
    console.log(r + " -> YAML");
    console.log(jsyaml.safeDump(template.Resources[r], { lineWidth: 1024 }));
  }

  // Line breaks can introduce YAML syntax (e.g. >-) that will put some variables
  // (e.g. AWS::Region) between quotes.
  // Single quotes must be removed for functions (e.g. Fn::GetAtt) to work.
  files['serverless.yml'] = jsyaml.safeDump(template, { lineWidth: 1024 }).replace(/'(!.+)'/g, "$1");
  
  return files;
}
github danilop / ServerlessByDesign / www / bundle.js View on Github external
var node = model.nodes[id];
    renderingRules[node.type].resource(status, node);
  }

  console.log(template); // Still in JSON
  console.log(JSON.stringify(template, null, 4)); // JSON -> text

  for (var r in template.Resources) {
    console.log(r + " -> YAML");
    console.log(jsyaml.safeDump(template.Resources[r], { lineWidth: 1024 }));
  }

  // Line breaks can introduce YAML syntax (e.g. >-) that will put some variables
  // (e.g. AWS::Region) between quotes.
  // Single quotes must be removed for functions (e.g. Fn::GetAtt) to work.
  files['serverless.yml'] = jsyaml.safeDump(template, { lineWidth: 1024 }).replace(/'(!.+)'/g, "$1");
  
  return files;
}
github DavidWells / aws-profile-manager / app / utils / parseServiceYaml.js View on Github external
export default function parseServiceYaml(path) {
  // CD into project directory
  process.chdir(path)
  const yamlPath = getServerlessYamlFilePath(path)
  const rawYAML = parseYaml(yamlPath)
  // Parse yamlAST and set Global. Todo: add to state
  parseYamlAST(yamlPath)
  // End AST parse.
  const serverless = new Serverless()
  return serverless.service.load()
    .then(() => {
      // TODO: pass in opts to popluate services https://github.com/serverless/serverless/blob/079c4459cc671fa54837d20015ce9176eee6d7cd/lib/classes/PluginManager.test.js#L218-L225
      const service = serverless.variables.populateService()
      const populatedService = {
        defaults: service.defaults,
        functions: service.functions,
        provider: service.provider,
        resources: service.resources,
        service: service.service,
      }
      // merge raw YAML and variable populated yaml
      return mergeYamlObjects(rawYAML, populatedService)
    })
}
github jacob-meacham / serverless-plugin-deploy-environment / test / index.spec.js View on Github external
test('Throws if no stage is found', t => {
  const sls = new Serverless()

  t.throws(() => initServerlessPlugin(sls), /No stage found.*/)
})
github jacob-meacham / serverless-plugin-deploy-environment / test / index.spec.js View on Github external
test('Merges environment', async t => {
  const sls = new Serverless()

  sls.service.custom = {
    defaults: {
      stage: 'test'
    },
    deploy: {
      environments: {
        default: { a: 1 },
        test: {
          b: 'foo'
        }
      }
    }
  }

  const plugin = initServerlessPlugin(sls)
github rajington / serverless-alexa-plugin / test / unit / serverless-alexa-plugin.js View on Github external
beforeEach(() => {
    serverless = new Serverless();
    serverless.service.resources = { Resources: {} };
    alexaPlugin = new ServerlessAlexaPlugin(serverless);
    alexaPlugin.serverless.service.service = 'new-service';
  });

serverless

Serverless Framework - Build web, mobile and IoT applications with serverless architectures using AWS Lambda, Azure Functions, Google CloudFunctions & more

MIT
Latest version published 6 months ago

Package Health Score

85 / 100
Full package analysis

Popular serverless functions