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!
CodePudding user response:
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
.