Skip to content

Commit f40fcec

Browse files
committed
private IAMPolicy created
1 parent 71caf11 commit f40fcec

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package airhacks.apigateway.control;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import software.amazon.awscdk.services.ec2.IVpc;
7+
import software.amazon.awscdk.services.iam.AnyPrincipal;
8+
import software.amazon.awscdk.services.iam.Effect;
9+
import software.amazon.awscdk.services.iam.PolicyDocument;
10+
import software.amazon.awscdk.services.iam.PolicyStatement;
11+
12+
public interface IAMPolicy {
13+
14+
static PolicyDocument restAPI(IVpc vpc){
15+
return PolicyDocument.Builder
16+
.create()
17+
.statements(List.of(allowStatement(),denyNotFrom(vpc.getVpcId())))
18+
.build();
19+
20+
}
21+
22+
static PolicyStatement allowStatement() {
23+
return PolicyStatement.Builder.create()
24+
.effect(Effect.ALLOW)
25+
.principals(List.of(new AnyPrincipal()))
26+
.actions(List.of("execute-api:Invoke"))
27+
.resources(List.of("execute-api:/*"))
28+
.build();
29+
}
30+
31+
static PolicyStatement denyNotFrom(String vpcId) {
32+
return PolicyStatement.Builder
33+
.create()
34+
.effect(Effect.DENY)
35+
.principals(List.of(new AnyPrincipal()))
36+
.actions(List.of("execute-api:Invoke"))
37+
.resources(List.of("execute-api:/*"))
38+
.conditions(Map.of("StringNotEquals",
39+
Map.of("aws:SourceVpc", vpcId)))
40+
.build();
41+
}
42+
43+
}

0 commit comments

Comments
 (0)