How to use the serverless-offline/src/functionHelper.getFunctionOptions function in serverless-offline

To help you get started, we’ve selected a few serverless-offline 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 CoorpAcademy / serverless-plugins / packages / serverless-offline-kinesis / index.js View on Github external
eventHandler(streamEvent, functionName, shardId, chunk, cb) {
    const streamName = streamEvent.arn.split('/')[1];
    this.serverless.cli.log(`${streamName} (λ: ${functionName})`);

    const {location = '.'} = this.service.custom['serverless-offline'];

    const __function = this.service.getFunction(functionName);
    const servicePath = join(this.serverless.config.servicePath, location);
    const funOptions = getFunctionOptions(__function, functionName, servicePath);
    const handler = createHandler(funOptions, {});

    const lambdaContext = createLambdaContext(__function, (err, data) => {
      this.serverless.cli.log(
        `[${err ? figures.cross : figures.tick}] ${JSON.stringify(data) || ''}`
      );
      cb(err, data);
    });

    const event = {
      Records: chunk.map(({SequenceNumber, ApproximateArrivalTimestamp, Data, PartitionKey}) => ({
        kinesis: {
          partitionKey: PartitionKey,
          kinesisSchemaVersion: '1.0',
          data: Data.toString('base64'),
          sequenceNumber: SequenceNumber
github msfidelis / serverless-offline-sqs-esmq / index.js View on Github external
eventHandler(queueEvent, functionName, messages, cb) {
    if (!messages) return cb();

    const streamName = this.getQueueName(queueEvent);
    this.serverless.cli.log(`${streamName} (λ: ${functionName})`);

    const {location = '.'} = getConfig(this.service, 'serverless-offline');

    const __function = this.service.getFunction(functionName);
    const servicePath = join(this.serverless.config.servicePath, location);
    const funOptions = getFunctionOptions(__function, functionName, servicePath);
    const handler = createHandler(funOptions, {});

    const lambdaContext = createLambdaContext(__function, (err, data) => {
      this.serverless.cli.log(
        `[${err ? figures.cross : figures.tick}] ${JSON.stringify(data) || ''}`
      );
      cb(err, data);
    });

    const event = {
      Records: messages.map(
        ({
          MessageId: messageId,
          ReceiptHandle: receiptHandle,
          Body: body,
          Attributes: attributes,
github tradle / serverless-iot-local / index.js View on Github external
Object.keys(this.service.functions).forEach(key => {
      const fun = this._getFunction(key)
      const funName = key
      const servicePath = path.join(this.serverless.config.servicePath, location)
      const funOptions = functionHelper.getFunctionOptions(fun, key, servicePath)
      this.debug(`funOptions ${JSON.stringify(funOptions, null, 2)} `)

      if (!fun.environment) {
        fun.environment = {}
      }

      fun.environment.AWS_LAMBDA_FUNCTION_NAME = `${this.service.service}-${this.service.provider.stage}-${funName}`

      this.debug('')
      this.debug(funName, 'runtime', runtime, funOptions.babelOptions || '')
      this.debug(`events for ${funName}:`)

      if (!(fun.events && fun.events.length)) {
        this.debug('(none)')
        return
      }
github mitipi / serverless-iot-offline / ruleHandler.js View on Github external
Object.keys(slsService.functions).forEach(key => {
    const fun = getFunction(key, slsService)
    const servicePath = path.join(serverless.config.servicePath, location)
    const funOptions = functionHelper.getFunctionOptions(fun, key, servicePath)

    if (!fun.environment) {
      fun.environment = {}
    }

    if (!(fun.events && fun.events.length)) {
      return
    }

    fun.events.forEach(event => {
      if (!event.iot) return

      const {iot} = event
      const {sql, actions} = iot

      const parsed = parseSelect(sql)
github mitipi / serverless-iot-offline / ruleHandler.js View on Github external
ruleConf.Actions.forEach((action) => {
        if (action.Lambda) {
          const awsFunName = action.Lambda.FunctionArn['Fn::GetAtt'][0]
          funName = _.lowerFirst(awsFunName).replace('LambdaFunction', '')
          fun = getFunction(funName, slsService)
          const servicePath = path.join(serverless.config.servicePath, location)
          funOptions = functionHelper.getFunctionOptions(fun, key, servicePath)

          if (!fun.environment) {
            fun.environment = {}
          }
        } else {
          actions.push(action)
        }
      })
github CoorpAcademy / serverless-plugins / packages / serverless-offline-kinesis / src / index.js View on Github external
const {location = '.'} = this.getConfig();

    const __function = this.service.getFunction(functionName);

    const {env} = process;
    const functionEnv = assignAll([
      {AWS_REGION: get('service.provider.region', this)},
      env,
      get('service.provider.environment', this),
      get('environment', __function)
    ]);
    process.env = functionEnv;

    const serviceRuntime = this.service.provider.runtime;
    const servicePath = join(this.serverless.config.servicePath, location);
    const funOptions = functionHelper.getFunctionOptions(
      __function,
      functionName,
      servicePath,
      serviceRuntime
    );
    const handler = functionHelper.createHandler(funOptions, this.getConfig());
    const lambdaContext = new LambdaContext(__function, this.service.provider, (err, data) => {
      this.serverless.cli.log(
        `[${err ? figures.cross : figures.tick}] ${functionName} ${JSON.stringify(data) || ''}`
      );
      cb(err, data);
    });

    const event = {
      Records: chunk.map(({SequenceNumber, ApproximateArrivalTimestamp, Data, PartitionKey}) => ({
        kinesis: {
github CoorpAcademy / serverless-plugins / packages / serverless-offline-sqs / src / index.js View on Github external
const __function = this.service.getFunction(functionName);

    const {env} = process;
    const functionEnv = assignAll([
      {AWS_REGION: get('service.provider.region', this)},
      env,
      get('service.provider.environment', this),
      get('environment', __function)
    ]);
    process.env = functionEnv;

    const serviceRuntime = this.service.provider.runtime;
    const servicePath = join(this.serverless.config.servicePath, location);

    const funOptions = functionHelper.getFunctionOptions(
      __function,
      functionName,
      servicePath,
      serviceRuntime
    );
    const handler = functionHelper.createHandler(funOptions, config);

    const lambdaContext = new LambdaContext(__function, this.service.provider, (err, data) => {
      this.serverless.cli.log(
        `[${err ? figures.cross : figures.tick}] ${functionName} ${JSON.stringify(data) || ''}`
      );
      cb(err, data);
    });

    const awsRegion = config.region || 'us-west-2';
    const awsAccountId = config.accountId || '000000000000';

serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project

MIT
Latest version published 7 days ago

Package Health Score

89 / 100
Full package analysis