aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.57k stars 1.55k forks source link

Can't delete SG rule of non default VPC SG #4248

Open eyal-solomon1 opened 1 year ago

eyal-solomon1 commented 1 year ago

Describe the bug

Trying to remove a rule from a specific security group but getting an error

Expected Behavior

Getting response as specified here - SDK docs with Return key as true

Current Behavior

Error log :

TypeError: Cannot read property 'Error' of undefined
    at loadEc2ErrorCode (/Users/x/Documents/x/x/node_modules/@aws-sdk/client-ec2/dist-cjs/protocols/Aws_ec2.js:63861:21)
    at deserializeAws_ec2RevokeSecurityGroupIngressCommandError (/Users/x/Documents/x/x/node_modules/@aws-sdk/client-ec2/dist-cjs/protocols/Aws_ec2.js:21550:23)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async /Users/x/Documents/x/x/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24
    at async /Users/x/Documents/x/x/node_modules/@aws-sdk/client-secrets-manager/node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:13:20
    at async StandardRetryStrategy.retry (/Users/x/Documents/x/x/node_modules/@aws-sdk/middleware-retry/dist-cjs/StandardRetryStrategy.js:51:46)
    at async /Users/x/Documents/x/x/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:6:22
    at async deploy (file:///Users/x/Documents/x/x/x)
    at async file:///Users/x/Documents/x/x/x {
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

Reproduction Steps

try {
  const input = {
          SecurityGroupRuleIds: [sgrId], // SG rule id
          GroupId: instance.sg, // SG id
        };
        const command = new RevokeSecurityGroupIngressCommand(input);
        const r = await client.send(command);
        console.log(r);
      }
} catch (e) {
    console.log(e);
}

Possible Solution

No response

Additional Information/Context

No response

SDK version used

@aws-sdk/client-ec2@3.178.0

Environment details (OS name and version, etc.)

Mac M1 macOS Monterey 12.6

eyal-solomon1 commented 1 year ago

Hey @ajredniwja can you assist here ?

ajredniwja commented 1 year ago

Hey @eyal-solomon1 thanks for opening this issue, I was not able to reproduce the issue:

I used the code below:

import { EC2Client, RevokeSecurityGroupIngressCommand } from "@aws-sdk/client-ec2"; // ES Modules import
(async() => {
    const client = new EC2Client("region: us-west-2");
    try {

        const input = {
            SecurityGroupRuleIds: ['sgr-984'], // SG rule id
            GroupId: "sg-0903093", // SG id
        };
        const command = new RevokeSecurityGroupIngressCommand(input);
        const r = await client.send(command);
        console.log(r);
    } catch (e) {
        console.log(e);
    }
})();

Response:

{
  '$metadata': {
    httpStatusCode: 200,
    requestId: '3s9pcebc-n778-3e30-92cf-ba669cc8700',
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  Return: true,
  UnknownIpPermissions: undefined
}

Version client:

    "dependencies": {
        "@aws-sdk/client-ec2": "^3.199.0"
    }

Can you try and run the same with the latest version?

Only difference is I am not on M1 mac but I dont think that should make any difference.

eyal-solomon1 commented 1 year ago
GroupId

Hi @ajredniwja ,thanks for your response

updated sdk package to @aws-sdk/client-ec2@3.204.0 and ran it with node v16.16.0

getting this error now :

Error: config.endpointProvider is not set.
    at getEndpointFromInstructions (/Users/../deployment_cli_tool/node_modules/@aws-sdk/middleware-endpoint/dist-cjs/adaptors/getEndpointFromInstructions.js:9:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

config initialization :

const client = new EC2Client();