Reputation: 3320
I have recently discovered the AWS CDK and I want to create an EC2 instance with a security group that allow all inbound traffic (that's for a lab).
Using the web interface, I can do it like this:
Now, I want to use the AWS CDK (in python) to create a security group like that. Is that possible ? If so, can I have a snippet please ?
Thanks!
Upvotes: 2
Views: 3505
Reputation: 3320
I finally found a solution.
# VPC
vpc = ec2.Vpc(self, "VPC",
nat_gateways=0,
subnet_configuration=[ec2.SubnetConfiguration(
name="public", subnet_type=ec2.SubnetType.PUBLIC)]
)
# security group allowing all traffic (in and out)
security_group = ec2.SecurityGroup(self, "SG", vpc=vpc)
security_group.add_ingress_rule(
peer=ec2.Peer.any_ipv4(),
connection=ec2.Port.all_traffic()
)
Warning, you should know what your doing when allowing all traffic.
Upvotes: 4