# APM for AWS Lambda 'APM Server transport error (ECONNREFUSED)'

**URL:** <https://discuss.elastic.co/t/apm-for-aws-lambda-apm-server-transport-error-econnrefused/169559>\
**Category:** APM\
**Created:** [February 22, 2019, 10:48am UTC](https://discuss.elastic.co/t/apm-for-aws-lambda-apm-server-transport-error-econnrefused/169559 "2019-02-22T10:48:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin\_Druzgala](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_druzgala/32/45030_2.png) [@Marcin\_Druzgala](https://discuss.elastic.co/u/Marcin_Druzgala)\
**Post date:** [February 22, 2019, 10:48am UTC](https://discuss.elastic.co/t/apm-for-aws-lambda-apm-server-transport-error-econnrefused/169559/1 "2019-02-22T10:48:55Z")

</div>

**Kibana version** : v6.6.0

**Elasticsearch version** :v6.6.0

**APM Server version** :v6.6.0

**APM Agent language and version** : "elastic-apm-node": "2.5.1"

So I have followed the steps described on the APM site to set APM plugin in my AWS lambda function: [https://www.elastic.co/guide/en/apm/agent/nodejs/1.x/lambda.html](https://www.elastic.co/guide/en/apm/agent/nodejs/1.x/lambda.html)

Then I've copied the config from APM configuration site on Kibana (APM -\> Setup instructions) but it doesn't work.

Here is the code:

```
import apm from 'elastic-apm-node/start'

const agent = apm.start({
  serviceName: 'test-api',
  secretToken: 'secret_value',
  serverUrl: 'https://hash.apm.eu-west-1.aws.cloud.es.io:443',
  logLevel: 'debug'
});

```

Then wrapped my function like that:

`export const testFunction = agent.lambda(async (event: APIGatewayEvent) => {});`

When I run the lambda and hit the endpoint related to this function I can see log in Cloudwatch that says:

"`APM Server transport error (ECONNREFUSED): connect ECONNREFUSED 127.0.0.1:8200`" So it looks like it's trying to connect to localhost instead of connecting with remote server?

I've tried the .NET Core APM as well and it's not throwing any error but it's not sending anything as well so what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![stephenbelanger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenbelanger/32/34880_2.png) [@stephenbelanger](https://discuss.elastic.co/u/stephenbelanger)\
**Post date:** [February 23, 2019, 1:16am UTC](https://discuss.elastic.co/t/apm-for-aws-lambda-apm-server-transport-error-econnrefused/169559/2 "2019-02-23T01:16:30Z")

</div>

You need to use `elastic-apm-node`, not `elastic-apm-node/start`. The start script calls the start method internally, and assumes your settings have been set using environment variables or a separate config file. Your code is effectively calling start twice. The first call doesn't have the serverUrl set, so it assumes localhost.

Also, the promise format isn't supported yet. We're working on it. Lambda support is still experimental.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 15, 2019, 9:16pm UTC](https://discuss.elastic.co/t/apm-for-aws-lambda-apm-server-transport-error-econnrefused/169559/3 "2019-03-15T21:16:33Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
