-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeptuneCdkTestStack.java
82 lines (71 loc) · 3.55 KB
/
NeptuneCdkTestStack.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.myorg;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.core.Stack;
import software.amazon.awscdk.core.StackProps;
import software.amazon.awscdk.services.ec2.ISubnet;
import software.amazon.awscdk.services.ec2.Port;
import software.amazon.awscdk.services.ec2.SecurityGroup;
import software.amazon.awscdk.services.ec2.Vpc;
import software.amazon.awscdk.services.iam.Effect;
import software.amazon.awscdk.services.iam.PolicyStatement;
import software.amazon.awscdk.services.iam.Role;
import software.amazon.awscdk.services.iam.RoleProps;
import software.amazon.awscdk.services.iam.ServicePrincipal;
import software.amazon.awscdk.services.neptune.CfnDBCluster;
import software.amazon.awscdk.services.neptune.CfnDBSubnetGroup;
public class NeptuneCdkTestStack extends Stack {
public NeptuneCdkTestStack(final Construct scope, final String id) {
this(scope, id, null);
}
public NeptuneCdkTestStack(final Construct scope, final String id, final StackProps props) {
super(scope, id, props);
Vpc vpc = Vpc.Builder.create(this, "TestVPC").maxAzs(3).build();
SecurityGroup neptuneSg = SecurityGroup.Builder.create(this, "NeptuneSecurityGroup").
vpc(vpc).
securityGroupName("NeptuneSecurityGroup").
build();
neptuneSg.addIngressRule(neptuneSg, Port.tcp(8182));
CfnDBSubnetGroup neptuneSubnetGroup = CfnDBSubnetGroup.Builder.create(this, "NeptuneSubnetGroup").
dbSubnetGroupName("neptune-subnet-group"). // not CamelCase
dbSubnetGroupDescription("Default subnet group").
subnetIds(vpc.getPrivateSubnets().stream().map(ISubnet::getSubnetId).collect(Collectors.toList())).
build();
Role bulkLoaderRole = new Role(this, "RDFBulkLoaderRole", RoleProps.builder().
assumedBy(new ServicePrincipal("rds.amazonaws.com")).
build());
bulkLoaderRole.addToPolicy(PolicyStatement.Builder.create().
effect(Effect.ALLOW).
actions(Arrays.asList("s3:Get*", "s3:List*")).
resources(Arrays.asList("arn:aws:s3:::*")).
build());
CfnDBCluster neptuneCluster = neptuneCluster(neptuneSubnetGroup, neptuneSg, bulkLoaderRole);
}
/**
* Setting <code>associatedRoles()</code> leads to <samp>Resolution error: Unable to resolve object tree with circular reference</samp>
* @param subnetGroup
* @param sg
* @param associatedRole
* @return
*/
public CfnDBCluster neptuneCluster(CfnDBSubnetGroup subnetGroup, SecurityGroup sg, Role associatedRole)
{
List<String> securityGroups = new ArrayList<>();
securityGroups.add(sg.getSecurityGroupId());
return CfnDBCluster.Builder.create(this, "NeptuneCluster").
dbSubnetGroupName(subnetGroup.getDbSubnetGroupName()).
vpcSecurityGroupIds(securityGroups).
associatedRoles(Arrays.asList(associatedRole)). // remove and the cdk synth runs without error
dbClusterIdentifier("OctopusTriplestoreCluster").
iamAuthEnabled(Boolean.TRUE).
deletionProtection(Boolean.TRUE).
engineVersion("1.0.2.2").
availabilityZones(getAvailabilityZones()).
port(8182).
deletionProtection(false).
build();
}
}