# Cannot construct a Request with a Request object that has already been used.

**URL:** <https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440>\
**Category:** Developer Q&A Forum\
**Tags:** custom-app, app-functions\
**Created:** [February 14, 2023, 3:18pm UTC](https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440 "2023-02-14T15:18:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarkusHobisch](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@MarkusHobisch](https://community.dynatrace.com/u/MarkusHobisch)\
**Post date:** [February 14, 2023, 3:18pm UTC](https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440/1 "2023-02-14T15:18:46Z")

</div>

Hi everyone!

I created an app function when triggered should create a new firewall.

```javascript
import { CreateFirewallCommand, NetworkFirewallClient } from '@aws-sdk/client-network-firewall';

export default async () => {
  const clientConfig = {
    region: 'us-east-1',
    credentials: {
      accessKeyId: '',
      secretAccessKey: '',
    },
  };

  const networkFirewallClient = new NetworkFirewallClient(clientConfig);

  const params = {
    FirewallName: 'VPC Firewall 2',
    // eslint-disable-next-line no-secrets/no-secrets
    FirewallPolicyArn: 'arn‌‌network-firewall:us-east-1:123456789012:firewall-policy/my-policy',
    VpcId: 'vpc-0af6340303f3168d3',
    SubnetMappings: [{ SubnetId: 'subnet-005fedf40f2e91595', Tier: 'PUBLIC' }],
  };

  try {
    const command = new CreateFirewallCommand(params);
    const response = await networkFirewallClient.send(command);
    console.log('Firewall successfully created:', response.Firewall.FirewallId);
    return response;
  } catch (err) {
    console.error('An error occurred:', err);
    throw err;
  }
};

```

The problem is that I am not able to make any successful request because AWS rejects it because it was already send. I got this error code back:

 ![MarkusHobisch_0-1676387539153.png](https://global.discourse-cdn.com/dynatrace/original/2X/f/fe185c5fcf11d98ca9c83bc37ee5d2078249afe5.png)

I am not sure now if this is a problem within the server.js file or if the problem is somewhere else? Do you have any suggestions?

Cheers

Markus

---

<div class="post-metadata">

**Author:** ![MarkusHobisch](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@MarkusHobisch](https://community.dynatrace.com/u/MarkusHobisch)\
**Post date:** [February 15, 2023, 8:22am UTC](https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440/2 "2023-02-15T08:22:20Z")

</div>

For better seachability I add the error code in text form:

```markup
[ERROR] /api/aws-firewall Fehler beim Erstellen der Firewall: Error: AWS SDK error wrapper for TypeError: Cannot construct a Request with a Request object that has already been used.
    at asSdkError (C:\Users\markus.hobisch\IdeaProjects\dynatrace-cpa\api\aws-firewall.js:5133:10)
    at C:\Users\markus.hobisch\IdeaProjects\dynatrace-cpa\api\aws-firewall.js:5182:21
    at async C:\Users\markus.hobisch\IdeaProjects\dynatrace-cpa\api\aws-firewall.js:4726:20
    at async Module.aws_firewall_default (C:\Users\markus.hobisch\IdeaProjects\dynatrace-cpa\api\aws-firewall.js:7144:22)
    at async Socket.<anonymous> (C:\Users\markus.hobisch\IdeaProjects\dynatrace-cpa\node_modules\@dynatrace\runtime-simulator\lib\server.js:395:53) {
  '$metadata': { attempts: 1, totalRetryDelay: 0 }

```

---

<div class="post-metadata">

**Author:** ![stefan\_eggersto](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/stefan_eggersto/32/34114_2.png) [@stefan\_eggersto](https://community.dynatrace.com/u/stefan_eggersto)\
**Post date:** [February 15, 2023, 8:27am UTC](https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440/3 "2023-02-15T08:27:33Z")

</div>

Hi Markus,

I can reproduce the issue. The internal error is following:

```auto
Exception has occurred: TypeError: Cannot construct a Request with a Request object that has already been used.
  at new Request (/node_modules/undici/lib/fetch/request.js:482:15)
  at fetch (/node_modules/undici/lib/fetch/index.js:137:21)
  at fetch (/node_modules/undici/index.js:111:20)
  at /node_modules/@dynatrace/runtime-simulator/lib/server.js:1:3560

```

We are further looking into the issue and will keep you posted.

---

<div class="post-metadata">

**Author:** ![stefan\_baumgart](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/stefan_baumgart/32/33707_2.png) [@stefan\_baumgart](https://community.dynatrace.com/u/stefan_baumgart)\
**Post date:** [February 15, 2023, 2:59pm UTC](https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440/4 "2023-02-15T14:59:38Z")

</div>

Did you try your Code with Node.js or a similar platform? Can you ensure that the problem lies within the execution via the Dynatrace Serverless Platform and not with the usage of the API?

---

<div class="post-metadata">

**Author:** ![MarkusHobisch](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@MarkusHobisch](https://community.dynatrace.com/u/MarkusHobisch)\
**Post date:** [February 15, 2023, 3:48pm UTC](https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440/5 "2023-02-15T15:48:13Z")

</div>

Hi Stefan,

did not try it out on Node.js so far but I can and would let you know.

---

<div class="post-metadata">

**Author:** ![MarkusHobisch](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@MarkusHobisch](https://community.dynatrace.com/u/MarkusHobisch)\
**Post date:** [February 15, 2023, 4:32pm UTC](https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440/6 "2023-02-15T16:32:56Z")

</div>

It works on Node.js. At least I get a different error (InvalidRequestException: Resource name has an invalid format) but this is fine because I didn’t checked the format so far.

---

<div class="post-metadata">

**Author:** ![stefan\_baumgart](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/stefan_baumgart/32/33707_2.png) [@stefan\_baumgart](https://community.dynatrace.com/u/stefan_baumgart)\
**Post date:** [February 15, 2023, 4:43pm UTC](https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440/7 "2023-02-15T16:43:28Z")

</div>

I also tried with the latest Deno installation and Chrome, and I’m also getting a different error. The error comes from calling `fetch` twice, and this looks like either a bundling issue or an execution issue on the runtime side.

---

<div class="post-metadata">

**Author:** ![stefan\_baumgart](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/stefan_baumgart/32/33707_2.png) [@stefan\_baumgart](https://community.dynatrace.com/u/stefan_baumgart)\
**Post date:** [February 15, 2023, 6:03pm UTC](https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440/8 "2023-02-15T18:03:30Z")

</div>

We identified the issue, and it’s a bug in the simulator. This error should not appear once the function is deployed.

---

<div class="post-metadata">

**Author:** ![MarkusHobisch](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@MarkusHobisch](https://community.dynatrace.com/u/MarkusHobisch)\
**Post date:** [February 16, 2023, 7:46am UTC](https://community.dynatrace.com/t/cannot-construct-a-request-with-a-request-object-that-has-already-been-used/38440/9 "2023-02-16T07:46:49Z")

</div>

Thanks for the update!
