vendredi 25 octobre 2019

Not able to test Stepfunction Execution via Lambda

I am trying to test my lambda function which invokes Step Function using AWS mock, but it is giving UnknownEndpoint: Inaccessible host: states.local-env.amazonaws.com

Here is my sample lambda function:

const AWS = require("aws-sdk");
const stepFunctions = new AWS.StepFunctions({region: 'local-env'});

exports.handler = async (event, context, config) => {

    const response = {
        statusCode: 200,
        body: event,
    };
    var params = {
        stateMachineArn: process.env.StateMachineARN, 
        input: JSON.stringify(event.body),
        name: 'Testing2'
    };

    stepFunctions.startExecution(params, function(err, data) {
        if (err) console.log(err, err.stack);
    });

    return response;
};

and there is my test file:

const index = require('./index')
var AWS = require('aws-sdk-mock');
const AWS_SDK = require('aws-sdk');

AWS.mock('StepFunctions', 'startExecution', function (params, callback){
  callback(null, "successfully started the execution");
});

const isTest = process.env.JEST_WORKER_ID;
const config = {
  convertEmptyValues: true,
  ...(isTest && {endpoint: 'localhost:8000', sslEnabled: false,region:'local-env'})
};


describe('Test Step Function Invocation', function () {
    it('verifies successful response', async () => {
      process.env.StateMachineARN = 'arn:aws:states:us-east-1:12345678:stateMachine:Testing';

      var event = { 
        "payload": "my_payload", 
        "data": "some-data", 
        "MVId": "00156"
      };

      const result = await index.handler(event,{},config);

      expect(result.statusCode).toEqual(200);
      expect(result.body).toBe(event);

    });
});

AWS.restore('StepFunctions');

I've been searching about this in the documentation and other resources but haven't found any solutions yet.

Aucun commentaire:

Enregistrer un commentaire