@@ -78,37 +78,38 @@ public Object handleRequest(SNSEvent event, Context context) {
78
78
ListStackResourcesResponse resources = cfn .listStackResources (req -> req
79
79
.stackName (cloudFormationEvent .getStackId ())
80
80
);
81
+ Map <String , Object > appConfig = new HashMap <>();
82
+ Map <String , Object > services = new HashMap <>();
81
83
for (StackResourceSummary resource : resources .stackResourceSummaries ()) {
82
84
// LOGGER.debug("Processing resource {} {} {} {}", resource.resourceType(),
83
85
// resource.resourceStatusAsString(), resource.logicalResourceId(),
84
86
// resource.physicalResourceId());
85
- if ("CREATE_COMPLETE" .equals (resource .resourceStatusAsString ())) {
86
- if ("AWS::ECR::Repository" .equals (resource .resourceType ())) {
87
- String ecrRepo = resource .physicalResourceId ();
88
- String serviceName = resource .logicalResourceId ();
89
- LOGGER .info ("Publishing appConfig update event for ECR repository {} {}" , serviceName ,
90
- ecrRepo );
91
- Map <String , Object > systemApiRequest = new HashMap <>();
92
- systemApiRequest .put ("resource" , "settings/config/" + serviceName + "/ECR_REPO" );
93
- systemApiRequest .put ("method" , "PUT" );
94
- systemApiRequest .put ("body" , Utils .toJson (Map .of ("value" , ecrRepo )));
95
- Utils .publishEvent (eventBridge , SAAS_BOOST_EVENT_BUS , EVENT_SOURCE , SYSTEM_API_CALL ,
96
- systemApiRequest );
97
- } else if ("AWS::Route53::HostedZone" .equals (resource .resourceType ())) {
98
- // Make this an event vs directly calling the Settings Service API because when this
99
- // CloudFormation stack first completes, the Settings Service may not even exist yet
100
- // Could also look at matching against UPDATE_COMPLETE
101
- // String hostedZoneId = resource.physicalResourceId();
102
- // LOGGER.info("Publishing appConfig update event for Route53 hosted zone {}", hostedZoneId);
103
- // Map<String, Object> systemApiRequest = new HashMap<>();
104
- // systemApiRequest.put("resource", "settings/HOSTED_ZONE");
105
- // systemApiRequest.put("method", "PUT");
106
- // //systemApiRequest.put("body", Utils.toJson(Map.of("value", ecrRepo)));
107
- // Utils.publishEvent(eventBridge, SAAS_BOOST_EVENT_BUS, EVENT_SOURCE, SYSTEM_API_CALL,
108
- // systemApiRequest);
87
+ if ("CREATE_COMPLETE" .equals (resource .resourceStatusAsString ())
88
+ && "AWS::ECR::Repository" .equals (resource .resourceType ())) {
89
+ String ecrRepo = resource .physicalResourceId ();
90
+ String serviceName = resource .logicalResourceId ();
91
+ LOGGER .info ("Publishing appConfig update event for ECR repository {} {}" , serviceName ,
92
+ ecrRepo );
93
+ services .put (serviceName , Map .of ("containerRepo" , ecrRepo ));
94
+ } else if ("CREATE_COMPLETE" .equals (resource .resourceStatusAsString ())
95
+ || "UPDATE_COMPLETE" .equals (resource .resourceStatusAsString ())) {
96
+ if ("AWS::Route53::HostedZone" .equals (resource .resourceType ())) {
97
+ // When CloudFormation stack first completes, the Settings Service won't even exist yet.
98
+ String hostedZoneId = resource .physicalResourceId ();
99
+ LOGGER .info ("Publishing appConfig update event for Route53 hosted zone {}" , hostedZoneId );
100
+ appConfig .put ("hostedZone" , hostedZoneId );
109
101
}
110
102
}
111
103
}
104
+ // Only fire one event for all the app config resources changes by this stack
105
+ if (!services .isEmpty ()) {
106
+ appConfig .put ("services" , services );
107
+ }
108
+ if (!appConfig .isEmpty ()) {
109
+ Utils .publishEvent (eventBridge , SAAS_BOOST_EVENT_BUS , EVENT_SOURCE ,
110
+ "Application Configuration Resource Changed" ,
111
+ appConfig );
112
+ }
112
113
} catch (SdkServiceException cfnError ) {
113
114
LOGGER .error ("cfn:ListStackResources error" , cfnError );
114
115
LOGGER .error (Utils .getFullStackTrace (cfnError ));
0 commit comments