Class CfnSecurityGroup

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

@Generated(value="jsii-pacmak/1.97.0 (build 729de35)", date="2024-04-18T17:54:15.776Z") @Stability(Stable) public class CfnSecurityGroup extends CfnResource implements IInspectable, ITaggable
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.

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();
 

See Also:
  • 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 software.constructs.Construct scope, @NotNull String id, @NotNull CfnSecurityGroupProps props)
      Parameters:
      scope - Scope in which this resource is defined. This parameter is required.
      id - Construct identifier for this resource (unique in its scope). 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 .
    • getAttrId

      @Stability(Stable) @NotNull public String getAttrId()
      The group name or group ID depending on whether the SG is created in default or specific VPC.
    • 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()
      Tag Manager which manages the tags for this resource.
      Specified by:
      getTags in interface ITaggable
    • getGroupDescription

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

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

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

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

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

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

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

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

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

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

      @Stability(Stable) @Nullable public List<CfnTag> getTagsRaw()
      Any tags assigned to the security group.
    • setTagsRaw

      @Stability(Stable) public void setTagsRaw(@Nullable List<CfnTag> value)
      Any tags assigned 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.