Class CfnSecurityGroup

java.lang.Object
software.amazon.jsii.JsiiObject
All Implemented Interfaces:
IConstruct, IDependable, IInspectable, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:38.918Z") @Stability(Stable) public class CfnSecurityGroup extends CfnResource implements IInspectable
A CloudFormation AWS::EC2::SecurityGroup.

Specifies a security group. To create a security group, use the VpcId property to specify the VPC for which to create the security group.

If you do not specify an egress rule, we add egress rules that allow IPv4 and IPv6 traffic on all ports and protocols to any destination. We do not add these rules if you specify your own egress rules. If you later remove your egress rules, we restore the default egress rules.

This type supports updates. For more information about updating stacks, see AWS CloudFormation Stacks Updates .

To cross-reference two security groups in the ingress and egress rules of those security groups, use the AWS::EC2::SecurityGroupEgress and AWS::EC2::SecurityGroupIngress resources to define your rules. Do not use the embedded ingress and egress rules in the AWS::EC2::SecurityGroup . Doing so creates a circular dependency, which AWS CloudFormation doesn't allow.

Example:

 // The code below shows an example of how to instantiate this type.
 // The values are placeholders you should change.
 import software.amazon.awscdk.services.ec2.*;
 CfnSecurityGroup cfnSecurityGroup = CfnSecurityGroup.Builder.create(this, "MyCfnSecurityGroup")
         .groupDescription("groupDescription")
         // the properties below are optional
         .groupName("groupName")
         .securityGroupEgress(List.of(EgressProperty.builder()
                 .ipProtocol("ipProtocol")
                 // the properties below are optional
                 .cidrIp("cidrIp")
                 .cidrIpv6("cidrIpv6")
                 .description("description")
                 .destinationPrefixListId("destinationPrefixListId")
                 .destinationSecurityGroupId("destinationSecurityGroupId")
                 .fromPort(123)
                 .toPort(123)
                 .build()))
         .securityGroupIngress(List.of(IngressProperty.builder()
                 .ipProtocol("ipProtocol")
                 // the properties below are optional
                 .cidrIp("cidrIp")
                 .cidrIpv6("cidrIpv6")
                 .description("description")
                 .fromPort(123)
                 .sourcePrefixListId("sourcePrefixListId")
                 .sourceSecurityGroupId("sourceSecurityGroupId")
                 .sourceSecurityGroupName("sourceSecurityGroupName")
                 .sourceSecurityGroupOwnerId("sourceSecurityGroupOwnerId")
                 .toPort(123)
                 .build()))
         .tags(List.of(CfnTag.builder()
                 .key("key")
                 .value("value")
                 .build()))
         .vpcId("vpcId")
         .build();
 
  • Field Details

    • CFN_RESOURCE_TYPE_NAME

      @Stability(Stable) public static final String CFN_RESOURCE_TYPE_NAME
      The CloudFormation resource type name for this resource class.
  • Constructor Details

    • CfnSecurityGroup

      protected CfnSecurityGroup(software.amazon.jsii.JsiiObjectRef objRef)
    • CfnSecurityGroup

      protected CfnSecurityGroup(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • CfnSecurityGroup

      @Stability(Stable) public CfnSecurityGroup(@NotNull Construct scope, @NotNull String id, @NotNull CfnSecurityGroupProps props)
      Create a new AWS::EC2::SecurityGroup.

      Parameters:
      scope -
      • scope in which this resource is defined.
      This parameter is required.
      id -
      • scoped id of the resource.
      This parameter is required.
      props -
      • resource properties.
      This parameter is required.
  • Method Details

    • inspect

      @Stability(Stable) public void inspect(@NotNull TreeInspector inspector)
      Examines the CloudFormation resource and discloses attributes.

      Specified by:
      inspect in interface IInspectable
      Parameters:
      inspector -
      • tree inspector to collect and process attributes.
      This parameter is required.
    • renderProperties

      @Stability(Stable) @NotNull protected Map<String,Object> renderProperties(@NotNull Map<String,Object> props)
      Overrides:
      renderProperties in class CfnResource
      Parameters:
      props - This parameter is required.
    • getAttrGroupId

      @Stability(Stable) @NotNull public String getAttrGroupId()
      The group ID of the specified security group, such as sg-94b3a1f6 .
    • getAttrVpcId

      @Stability(Stable) @NotNull public String getAttrVpcId()
      The physical ID of the VPC.

      You can obtain the physical ID by using a reference to an AWS::EC2::VPC , such as: { "Ref" : "myVPC" } .

    • getCfnProperties

      @Stability(Stable) @NotNull protected Map<String,Object> getCfnProperties()
      Overrides:
      getCfnProperties in class CfnResource
    • getTags

      @Stability(Stable) @NotNull public TagManager getTags()
      Any tags assigned to the security group.
    • getGroupDescription

      @Stability(Stable) @NotNull public String getGroupDescription()
      A description for the security group.

      Constraints: Up to 255 characters in length

      Valid characters: a-z, A-Z, 0-9, spaces, and ._-:/()#,@[]+=&;{}!$*

    • setGroupDescription

      @Stability(Stable) public void setGroupDescription(@NotNull String value)
      A description for the security group.

      Constraints: Up to 255 characters in length

      Valid characters: a-z, A-Z, 0-9, spaces, and ._-:/()#,@[]+=&;{}!$*

    • getGroupName

      @Stability(Stable) @Nullable public String getGroupName()
      The name of the security group.

      Constraints: Up to 255 characters in length. Cannot start with sg- .

      Valid characters: a-z, A-Z, 0-9, spaces, and ._-:/()#,@[]+=&;{}!$*

    • setGroupName

      @Stability(Stable) public void setGroupName(@Nullable String value)
      The name of the security group.

      Constraints: Up to 255 characters in length. Cannot start with sg- .

      Valid characters: a-z, A-Z, 0-9, spaces, and ._-:/()#,@[]+=&;{}!$*

    • getSecurityGroupEgress

      @Stability(Stable) @Nullable public Object getSecurityGroupEgress()
      The outbound rules associated with the security group.

      There is a short interruption during which you cannot connect to the security group.

    • setSecurityGroupEgress

      @Stability(Stable) public void setSecurityGroupEgress(@Nullable IResolvable value)
      The outbound rules associated with the security group.

      There is a short interruption during which you cannot connect to the security group.

    • setSecurityGroupEgress

      @Stability(Stable) public void setSecurityGroupEgress(@Nullable List<Object> value)
      The outbound rules associated with the security group.

      There is a short interruption during which you cannot connect to the security group.

    • getSecurityGroupIngress

      @Stability(Stable) @Nullable public Object getSecurityGroupIngress()
      The inbound rules associated with the security group.

      There is a short interruption during which you cannot connect to the security group.

    • setSecurityGroupIngress

      @Stability(Stable) public void setSecurityGroupIngress(@Nullable IResolvable value)
      The inbound rules associated with the security group.

      There is a short interruption during which you cannot connect to the security group.

    • setSecurityGroupIngress

      @Stability(Stable) public void setSecurityGroupIngress(@Nullable List<Object> value)
      The inbound rules associated with the security group.

      There is a short interruption during which you cannot connect to the security group.

    • getVpcId

      @Stability(Stable) @Nullable public String getVpcId()
      The ID of the VPC for the security group.
    • setVpcId

      @Stability(Stable) public void setVpcId(@Nullable String value)
      The ID of the VPC for the security group.