cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

MarkusHobisch
Dynatrace Participant
Dynatrace Participant

Hi everyone!

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

 

 

 

 

 

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

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

8 REPLIES 8

MarkusHobisch
Dynatrace Participant
Dynatrace Participant

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

[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 }

Hi Markus,

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

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.

stefan_baumgart
Dynatrace Advocate
Dynatrace Advocate

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?

Hi Stefan,

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

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. 

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.

stefan_baumgart
Dynatrace Advocate
Dynatrace Advocate

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

Thanks for the update!

Featured Posts