Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

engine.start() does not work properly on AWS Lambda #185

Closed
rhlsthrm opened this issue Sep 27, 2017 · 1 comment
Closed

engine.start() does not work properly on AWS Lambda #185

rhlsthrm opened this issue Sep 27, 2017 · 1 comment

Comments

@rhlsthrm
Copy link

I am trying to deploy an endpoint on AWS Lambda that implements a web3 provider engine. I am trying to use a private key to sign transactions with Web3 and INFURA. Here is some of my code (private data redacted):

module.exports.handler = (event, context, callback) => { // lambda boilerplate
  // get wallet from private key
  const myWallet = Wallet.fromV3(
    JSON.stringify({
      address: '<ADDRESS>',
      crypto: {
        // crypto params
    }),
    '<PASSWORD>',
    true
  )
  // console.log(web3)
  const providerUrl = 'https://kovan.infura.io/<INFURA_TOKEN>'
  const engine = new ProviderEngine()
  engine.addProvider(new WalletSubprovider(myWallet, {}))
  engine.addProvider(
    new Web3Subprovider(new Web3.providers.HttpProvider(providerUrl))
  )
  let web3 = new Web3(engine)
  engine.start()
  web3.eth.getBlockNumber((err, result) => {
    callback(
      null,
      success({
        message: 'Web3 is connected!',
        block: result
      })
    )
  })

Everything works fine when I run locally, but when I try to run it on AWS Lambda, I get timeout errors. I have pinpointed the issue to engine.start(). Is there a dependency with engine.start() on a specific Node version (Lambda runs 6.10)? Is there some sort of websocket or connection being opened that is not supported by Lambda?

@kumavis
Copy link
Member

kumavis commented Apr 10, 2018

@rhlsthrm at some point we changed the default provider to fetch, maybe that was the issue. It was replaced with a polyfill.
additionally engine.start() now takes a callback that will catch the error.

Let me know if the latest version does not work on aws lambdas

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants