static async getDDBItem()

in source/services/policyManager/lib/PolicyHelper.ts [67:124]


  static async getDDBItem(
    primaryKey: string,
    sortKey: string,
    table: string
  ): Promise<{
    [key: string]: AttributeValue;
  }> {
    logger.debug({
      label: "FMSHelper/getDDBItem",
      message: `policy item ${JSON.stringify({
        policy: primaryKey,
        region: sortKey,
      })}`,
    });
    try {
      const ddb = new DynamoDBClient({
        customUserAgent,
        logger: serviceLogger,
      });
      const params = {
        Key: {
          PolicyName: {
            S: primaryKey,
          },
          Region: {
            S: sortKey,
          },
        },
        TableName: table,
      };
      const response = await ddb.send(new GetItemCommand(params));
      logger.debug({
        label: "FMSHelper/getDDBItem",
        message: `ddb item fetched ${JSON.stringify(response)}`,
      });
      if (!response.Item) throw new Error("ResourceNotFound");
      else return response.Item;
    } catch (e) {
      if (e.message === "ResourceNotFound") {
        logger.warn({
          label: "FMSHelper/getDDBItem",
          message: `item not found ${JSON.stringify({
            primaryKey,
            sortKey,
            table,
          })}`,
        });
        throw new Error("ResourceNotFound");
      }
      throw new Error(
        `error getting ddb item ${JSON.stringify({
          primaryKey,
          sortKey,
          table,
        })}`
      );
    }
  }