@@ -26,99 +26,99 @@ EC2-Classic and EC2-VPC, see :ec2-ug:`Supported Platforms <ec2-supported-platfor
2626For more information about creating a security group using the |EC2 | console, see :ec2-ug: `Amazon
2727EC2 Security Groups <using-network-security> ` in the |EC2-ug |.
2828
29- ** To create a security group **
29+ .. topic :: To create a security group
3030
31- 1 . Create and initialize a :java-api: `CreateSecurityGroupRequest
32- <services/ec2/model/CreateSecurityGroupRequest> ` instance. Use the :java-ref: `withGroupName
33- <com/amazonaws/services/ec2/model/CreateSecurityGroupRequest.html#withGroupName(java.lang.String)> `
34- method to set the security group name, and the :java-ref: `withDescription
35- <com/amazonaws/services/ec2/model/CreateSecurityGroupRequest.html#withDescription(java.lang.String)> `
36- method to set the security group description, as follows:
31+ # . Create and initialize a :java-api: `CreateSecurityGroupRequest
32+ <services/ec2/model/CreateSecurityGroupRequest> ` instance. Use the :java-ref: `withGroupName
33+ <com/amazonaws/services/ec2/model/CreateSecurityGroupRequest.html#withGroupName(java.lang.String)> `
34+ method to set the security group name, and the :java-ref: `withDescription
35+ <com/amazonaws/services/ec2/model/CreateSecurityGroupRequest.html#withDescription(java.lang.String)> `
36+ method to set the security group description, as follows:
3737
38- .. code-block :: java
38+ .. code-block :: java
3939
40- CreateSecurityGroupRequest csgr = new CreateSecurityGroupRequest ();
40+ CreateSecurityGroupRequest csgr = new CreateSecurityGroupRequest ();
4141
42- csgr. withGroupName(" JavaSecurityGroup" ). withDescription(" My security group" );
42+ csgr. withGroupName(" JavaSecurityGroup" ). withDescription(" My security group" );
4343
44- The security group name must be unique within the AWS region in which you initialize your |EC2 |
45- client. You must use US-ASCII characters for the security group name and description.
44+ The security group name must be unique within the AWS region in which you initialize your |EC2 |
45+ client. You must use US-ASCII characters for the security group name and description.
4646
47- 2 . Pass the request object as a parameter to the :java-ref: `createSecurityGroup
48- <com/amazonaws/services/ec2/AmazonEC2.html#createSecurityGroup%28com.amazonaws.services.ec2.model.CreateSecurityGroupRequest%29> `
49- method. The method returns a :java-api: `CreateSecurityGroupResult
50- <services/ec2/model/CreateSecurityGroupResult> ` object, as follows:
47+ # . Pass the request object as a parameter to the :java-ref: `createSecurityGroup
48+ <com/amazonaws/services/ec2/AmazonEC2.html#createSecurityGroup%28com.amazonaws.services.ec2.model.CreateSecurityGroupRequest%29> `
49+ method. The method returns a :java-api: `CreateSecurityGroupResult
50+ <services/ec2/model/CreateSecurityGroupResult> ` object, as follows:
5151
52- .. code-block :: java
52+ .. code-block :: java
5353
54- CreateSecurityGroupResult createSecurityGroupResult =
55- amazonEC2Client. createSecurityGroup(createSecurityGroupRequest);
54+ CreateSecurityGroupResult createSecurityGroupResult =
55+ amazonEC2Client. createSecurityGroup(createSecurityGroupRequest);
5656
57- If you attempt to create a security group with the same name as an existing security group,
58- :code: `createSecurityGroup ` throws an exception.
57+ If you attempt to create a security group with the same name as an existing security group,
58+ :code: `createSecurityGroup ` throws an exception.
5959
6060By default, a new security group does not allow any inbound traffic to your |EC2 | instance. To allow
6161inbound traffic, you must explicitly authorize security group ingress. You can authorize ingress for
6262individual IP addresses, for a range of IP addresses, for a specific protocol, and for TCP/UDP
6363ports.
6464
65- ** To authorize security group ingress **
65+ .. topic :: To authorize security group ingress
6666
67- 1 . Create and initialize an :java-api: `IpPermission <services/ec2/model/IpPermission> ` instance.
68- Use the :java-ref: `withIpRanges
69- <com/amazonaws/services/ec2/model/IpPermission.html#withIpRanges(java.lang.String...)> ` method
70- to set the range of IP addresses to authorize ingress for, and use the :java-ref: `withIpProtocol
71- <com/amazonaws/services/ec2/model/IpPermission.html#withIpProtocol(java.lang.String)> ` method to
72- set the IP protocol. Use the :java-ref: `withFromPort
73- <com/amazonaws/services/ec2/model/IpPermission.html#withFromPort(java.lang.Integer)> ` and
74- :java-ref: `withToPort
75- <com/amazonaws/services/ec2/model/IpPermission.html#withToPort(java.lang.Integer)> ` methods to
76- specify range of ports to authorize ingress for, as follows:
67+ # . Create and initialize an :java-api: `IpPermission <services/ec2/model/IpPermission> ` instance.
68+ Use the :java-ref: `withIpRanges
69+ <com/amazonaws/services/ec2/model/IpPermission.html#withIpRanges(java.lang.String...)> ` method
70+ to set the range of IP addresses to authorize ingress for, and use the :java-ref: `withIpProtocol
71+ <com/amazonaws/services/ec2/model/IpPermission.html#withIpProtocol(java.lang.String)> ` method to
72+ set the IP protocol. Use the :java-ref: `withFromPort
73+ <com/amazonaws/services/ec2/model/IpPermission.html#withFromPort(java.lang.Integer)> ` and
74+ :java-ref: `withToPort
75+ <com/amazonaws/services/ec2/model/IpPermission.html#withToPort(java.lang.Integer)> ` methods to
76+ specify range of ports to authorize ingress for, as follows:
7777
78- .. code-block :: java
78+ .. code-block :: java
7979
80- IpPermission ipPermission =
81- new IpPermission ();
80+ IpPermission ipPermission =
81+ new IpPermission ();
8282
83- ipPermission. withIpRanges(" 111.111.111.111/32" , " 150.150.150.150/32" )
84- .withIpProtocol(" tcp" )
85- .withFromPort(22 )
86- .withToPort(22 );
83+ ipPermission. withIpRanges(" 111.111.111.111/32" , " 150.150.150.150/32" )
84+ .withIpProtocol(" tcp" )
85+ .withFromPort(22 )
86+ .withToPort(22 );
8787
88- All the conditions that you specify in the :code: `IpPermission ` object must be met in order for
89- ingress to be allowed.
88+ All the conditions that you specify in the :code: `IpPermission ` object must be met in order for
89+ ingress to be allowed.
9090
91- Specify the IP address using CIDR notation. If you specify the protocol as TCP/UDP, you must
92- provide a source port and a destination port. You can authorize ports only if you specify TCP or
93- UDP.
91+ Specify the IP address using CIDR notation. If you specify the protocol as TCP/UDP, you must
92+ provide a source port and a destination port. You can authorize ports only if you specify TCP or
93+ UDP.
9494
95- 2 . Create and initialize an :java-api: `AuthorizeSecurityGroupIngressRequest
96- <services/ec2/model/AuthorizeSecurityGroupEgressRequest> ` instance. Use the
97- :code: `withGroupName ` method to specify the security group name, and pass the
98- :code: `IpPermission ` object you initialized earlier to the :java-ref: `withIpPermissions
99- <com/amazonaws/services/ec2/model/AuthorizeSecurityGroupEgressRequest.html#withIpPermissions(com.amazonaws.services.ec2.model.IpPermission...)> `
100- method, as follows:
95+ # . Create and initialize an :java-api: `AuthorizeSecurityGroupIngressRequest
96+ <services/ec2/model/AuthorizeSecurityGroupEgressRequest> ` instance. Use the
97+ :code: `withGroupName ` method to specify the security group name, and pass the
98+ :code: `IpPermission ` object you initialized earlier to the :java-ref: `withIpPermissions
99+ <com/amazonaws/services/ec2/model/AuthorizeSecurityGroupEgressRequest.html#withIpPermissions(com.amazonaws.services.ec2.model.IpPermission...)> `
100+ method, as follows:
101101
102- .. code-block :: java
102+ .. code-block :: java
103103
104- AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest =
105- new AuthorizeSecurityGroupIngressRequest ();
104+ AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest =
105+ new AuthorizeSecurityGroupIngressRequest ();
106106
107- authorizeSecurityGroupIngressRequest. withGroupName(" JavaSecurityGroup" )
108- .withIpPermissions(ipPermission);
107+ authorizeSecurityGroupIngressRequest. withGroupName(" JavaSecurityGroup" )
108+ .withIpPermissions(ipPermission);
109109
110- 3 . Pass the request object into the :java-ref: `authorizeSecurityGroupIngress
111- <com/amazonaws/services/ec2/AmazonEC2.html#authorizeSecurityGroupEgress%28com.amazonaws.services.ec2.model.AuthorizeSecurityGroupEgressRequest%29> `
112- method, as follows:
110+ # . Pass the request object into the :java-ref: `authorizeSecurityGroupIngress
111+ <com/amazonaws/services/ec2/AmazonEC2.html#authorizeSecurityGroupEgress%28com.amazonaws.services.ec2.model.AuthorizeSecurityGroupEgressRequest%29> `
112+ method, as follows:
113113
114- .. code-block :: java
114+ .. code-block :: java
115115
116- amazonEC2Client. authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);
116+ amazonEC2Client. authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);
117117
118- If you call :code: `authorizeSecurityGroupIngress ` with IP addresses for which ingress is already
119- authorized, the method throws an exception. Create and initialize a new :code: `IpPermission `
120- object to authorize ingress for different IPs, ports, and protocols before calling
121- :code: `AuthorizeSecurityGroupIngress `.
118+ If you call :code: `authorizeSecurityGroupIngress ` with IP addresses for which ingress is already
119+ authorized, the method throws an exception. Create and initialize a new :code: `IpPermission `
120+ object to authorize ingress for different IPs, ports, and protocols before calling
121+ :code: `AuthorizeSecurityGroupIngress `.
122122
123123Whenever you call the :code: `authorizeSecurityGroupIngress ` or
124124:java-ref: `authorizeSecurityGroupEgress
0 commit comments