Skip to content

Commit

Permalink
fix: do not fail deployment when missing permission to get thing grou…
Browse files Browse the repository at this point in the history
…p hierarchy (#1137)
  • Loading branch information
shaguptashaikh committed Nov 23, 2021
1 parent ca80f96 commit 739e22b
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.aws.greengrass.util.Coerce;
import com.vdurmont.semver4j.Semver;
import lombok.Getter;
import software.amazon.awssdk.services.greengrassv2data.model.GreengrassV2DataException;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -194,6 +195,18 @@ private Map<String, Set<ComponentIdentifier>> getNonTargetGroupToRootPackagesMap
Optional<Set<String>> groupsForDeviceOpt;
try {
groupsForDeviceOpt = thingGroupHelper.listThingGroupsForDevice(retryCount);
} catch (GreengrassV2DataException e) {
if (e.statusCode() == 403) {
// Getting group hierarchy requires permission to call the ListThingGroupsForCoreDevice API which
// may not be configured on existing IoT Thing policy in use for current device, log a warning in
// that case and move on.
logger.atWarn().setCause(e).log("Failed to get thing group hierarchy. Deployment will proceed. "
+ "To automatically clean up unused components, please add "
+ "greengrass:ListThingGroupsForCoreDevice permission to your IoT Thing policy.");
groupsForDeviceOpt = getPersistedMembershipInfo();
} else {
throw new DeploymentTaskFailureException("Error fetching thing group information", e);
}
} catch (Exception e) {
if (isLocalDeployment && ThingGroupHelper.DEVICE_OFFLINE_INDICATIVE_EXCEPTIONS.contains(e.getClass())) {
logger.atWarn().setCause(e).log("Failed to get thing group hierarchy, local deployment will proceed");
Expand Down

0 comments on commit 739e22b

Please sign in to comment.