Skip to content

Add security group examples #799

@cremich

Description

@cremich

It would be great do find some examples how to create new security groups with ingress and egress rules. Currently its hard to find some hints how to provide the parameters for addIngressRule of a newly created securitygroup.

Here a short typescript sample that creates a new vpc, a security-group and an ec2-instance. Maybe it is helpul:

    const vpc = new ec2.VpcNetwork(this, 'NewVPC');

    let mySecurityGroup = new ec2.SecurityGroup(this, 'NewSecurityGroup', {
      description: 'Allow ssh access to ec2 instances',
      groupName: 'ec2-ssh-access',
      vpc: vpc
    });
    mySecurityGroup.addIngressRule(new ec2.AnyIPv4(), new ec2.TcpPort(22), 'allow ssh access from any ipv4 ip');

    new ec2.cloudformation.InstanceResource(this, 'Ec2Instance', {
        imageId: ' ami-0f5dbc86dd9cbf7a8',
        securityGroupIds: [ mySecurityGroup.securityGroupId],
        instanceType: 't2.micro',
        tags: [{
          key: 'Name',
          value: 'my-new-ec2-instance'
        }]
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions