如何使用NodeJS将安全组添加到已经运行的EC2实例中?

发布于 2025-01-23 18:33:40 字数 122 浏览 4 评论 0原文

标题几乎说明了所有内容,但为了明确说明,我不想

(1)使用该控制台或 (2)使用CLI,

我想使用nodejs动态添加SG。令我震惊的是,在AWS文档中没有明显的答案,但是,如果有的话,我当然找不到它!

the title says almost everything, but just to make it clear, I DON'T want to

(1) use the console, OR
(2) use the CLI,

I want to add a SG dynamically using nodejs. I am shocked that there is not an obvious answer to this in the AWS documentation, but, if there is, I certainly can't find it!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许一世地老天荒 2025-01-30 18:33:40

您可以通过 modifynetworktork interflibute /代码>参数:

更改网络接口的安全组。您指定的新组替换了当前集。您必须至少指定一个组,即使仅是VPC中的默认安全组。您必须指定安全组的ID,而不是名称。

因此,您必须首先获得实例的networkInterfaceid(一个实例可以具有多个接口)。您可以使用 docidentIxinstances 。拥有NetworkInterfaceID后,您可以使用modifynetworkInterfaceAttribute修改其SGS。

You do this through modifyNetworkInterfaceAttribute which takes Groups parameter:

Changes the security groups for the network interface. The new set of groups you specify replaces the current set. You must specify at least one group, even if it's just the default security group in the VPC. You must specify the ID of the security group, not the name.

So you have to get NetworkInterfaceId of your instance (an instance can have multiple interfaces) first. You can do that using describeInstances. Once you have the NetworkInterfaceId you modify their SGs using modifyNetworkInterfaceAttribute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文