Skip to content

Commit 5484051

Browse files
authored
Fixed issue 16 (#17)
* Fixed issue 16 * minor change * minor change * updated register.sh * Updated to cloudformation-java-plugin 2.0.5, minor updates to register.sh and CreateHandler.java * pre-commit check
1 parent f6850ce commit 5484051

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

.rpdk-config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"artifact_type": "RESOURCE",
23
"typeName": "AWSUtility::CloudFormation::CommandRunner",
34
"language": "java",
45
"runtime": "java8",
@@ -12,5 +13,6 @@
1213
"commandrunner"
1314
],
1415
"protocolVersion": "2.0.0"
15-
}
16+
},
17+
"executableEntrypoint": "software.awsutility.cloudformation.commandrunner.HandlerWrapperExecutable"
1618
}

awsutility-cloudformation-commandrunner.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
"cloudformation:DeleteStack",
6666
"cloudformation:CreateStack",
6767
"cloudformation:DescribeStacks",
68-
"cloudwatch:CreateLogStream",
69-
"cloudwatch:DescribeLogGroups",
70-
"cloudwatch:PutMetricData",
68+
"logs:CreateLogStream",
69+
"logs:DescribeLogGroups",
70+
"logs:PutMetricData",
7171
"ssm:GetParameter",
7272
"ssm:PutParameter",
7373
"iam:PassRole",
@@ -80,7 +80,7 @@
8080
"read": {
8181
"permissions": [
8282
"ssm:GetParameter",
83-
"cloudwatch:PutMetricData"
83+
"logs:PutMetricData"
8484
]
8585
},
8686
"delete": {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<dependency>
3939
<groupId>software.amazon.cloudformation</groupId>
4040
<artifactId>aws-cloudformation-rpdk-java-plugin</artifactId>
41-
<version>2.0.0</version>
41+
<version>2.0.5</version>
4242
</dependency>
4343
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
4444
<dependency>

resource-role.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ Resources:
2626
- "cloudformation:CreateStack"
2727
- "cloudformation:DeleteStack"
2828
- "cloudformation:DescribeStacks"
29-
- "cloudwatch:CreateLogStream"
30-
- "cloudwatch:DescribeLogGroups"
31-
- "cloudwatch:PutMetricData"
3229
- "ec2:AuthorizeSecurityGroupEgress"
3330
- "ec2:AuthorizeSecurityGroupIngress"
3431
- "ec2:CreateSecurityGroup"
@@ -46,6 +43,9 @@ Resources:
4643
- "iam:SimulatePrincipalPolicy"
4744
- "kms:Decrypt"
4845
- "kms:Encrypt"
46+
- "logs:CreateLogStream"
47+
- "logs:DescribeLogGroups"
48+
- "logs:PutMetricData"
4949
- "ssm:DeleteParameter"
5050
- "ssm:GetParameter"
5151
- "ssm:PutParameter"

scripts/register.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ echo Creating Execution Role...
3838
role_stack_id=`aws cloudformation create-stack --stack-name awsutility-cloudformation-commandrunner-execution-role-stack --template-body file://resource-role.yaml --capabilities CAPABILITY_IAM --query StackId --output text 2>> registration_logs.log`
3939

4040
if ! [ $? -eq 0 ]; then
41-
echo Execution role already exists.
42-
echo Creating Execution Role skipped.
41+
#Check if any updates can be made if it already exists
42+
role_stack_id=`aws cloudformation update-stack --stack-name awsutility-cloudformation-commandrunner-execution-role-stack --template-body file://resource-role.yaml --capabilities CAPABILITY_IAM --query StackId --output text 2>> registration_logs.log`
43+
if ! [ $? -eq 0 ]; then
44+
echo Execution role already exists, no changes to be made.
45+
echo Creating Execution Role skipped.
46+
fi
4347
fi
4448

4549
stack_progress=`aws cloudformation describe-stacks --stack-name awsutility-cloudformation-commandrunner-execution-role-stack --query Stacks[0].StackStatus --output text`

src/main/java/software/awsutility/cloudformation/commandrunner/CreateHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
177177
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().build();
178178
DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest();
179179
describeVpcsRequest.withFilters(new Filter("isDefault").withValues("true"));
180-
DescribeVpcsResult describeVpcsResult = proxy.injectCredentialsAndInvoke(describeVpcsRequest, ec2::describeVpcs);
180+
DescribeVpcsResult describeVpcsResult = proxy.<DescribeVpcsRequest,DescribeVpcsResult>injectCredentialsAndInvoke(describeVpcsRequest, ec2::describeVpcs);
181181
String vpcId = describeVpcsResult.getVpcs().get(0).getVpcId();
182182
if (vpcId == null || vpcId.isEmpty()) {
183183
System.out.println("No default VPC found in this region, please specify a subnet using the NetworkConfiguration property.");
@@ -190,7 +190,7 @@ public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
190190
VpcId.setParameterValue(vpcId);
191191
DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
192192
describeSubnetsRequest.withFilters(new Filter("vpc-id").withValues(vpcId));
193-
DescribeSubnetsResult describeSubnetsResult = proxy.injectCredentialsAndInvoke(describeSubnetsRequest, ec2::describeSubnets);
193+
DescribeSubnetsResult describeSubnetsResult = proxy.<DescribeSubnetsRequest,DescribeSubnetsResult>injectCredentialsAndInvoke(describeSubnetsRequest, ec2::describeSubnets);
194194
String subnetId = describeSubnetsResult.getSubnets().get(describeSubnetsResult.getSubnets().size()-1).getSubnetId();
195195
if (subnetId == null || subnetId.isEmpty()) {
196196
System.out.println("Default VPC has no subnets. Please specify a subnet using the NetworkConfiguration property");
@@ -235,7 +235,7 @@ else if ((model.getSubnetId() != null && model.getSecurityGroupId() == null) ||
235235
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().build();
236236
DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
237237
describeSubnetsRequest.withFilters(new Filter("subnet-id").withValues(model.getSubnetId()));
238-
DescribeSubnetsResult describeSubnetsResult = proxy.injectCredentialsAndInvoke(describeSubnetsRequest, ec2::describeSubnets);
238+
DescribeSubnetsResult describeSubnetsResult = proxy.<DescribeSubnetsRequest,DescribeSubnetsResult>injectCredentialsAndInvoke(describeSubnetsRequest, ec2::describeSubnets);
239239
String vpcId = describeSubnetsResult.getSubnets().get(0).getVpcId();
240240
VpcId.setParameterValue(vpcId);
241241
parameters.add(VpcId);
@@ -305,7 +305,7 @@ else if ((model.getSubnetId() == null && model.getSecurityGroupId() != null) ||
305305
wait.setStackName(stackName);
306306
String stackStatus = "Unknown";
307307
String stackReason = "";
308-
List<Stack> stacks = proxy.injectCredentialsAndInvoke(wait, stackbuilder::describeStacks).getStacks();
308+
List<Stack> stacks = proxy.<DescribeStacksRequest,DescribeStacksResult>injectCredentialsAndInvoke(wait, stackbuilder::describeStacks).getStacks();
309309
if (
310310
stacks.get(0).getStackStatus().equals(StackStatus.CREATE_COMPLETE.toString()) ||
311311
stacks.get(0).getStackStatus().equals(StackStatus.CREATE_FAILED.toString()) ||

0 commit comments

Comments
 (0)