Skip to content

Commit

Permalink
Merge pull request #1533 from RoadieHQ/s3-tag-mods
Browse files Browse the repository at this point in the history
Handle cases where S3 buckets don't have a tag set
  • Loading branch information
Xantier authored Aug 6, 2024
2 parents a515217 + 91f508a commit 4fa0b2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-kiwis-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roadiehq/catalog-backend-module-aws': patch
---

Handle cases where S3 buckets don't have a tag set.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { ANNOTATION_VIEW_URL, ResourceEntity } from '@backstage/catalog-model';
import { S3 } from '@aws-sdk/client-s3';
import { S3, Tag } from '@aws-sdk/client-s3';
import * as winston from 'winston';
import { Config } from '@backstage/config';
import { AWSEntityProvider } from './AWSEntityProvider';
Expand Down Expand Up @@ -94,8 +94,17 @@ export class AWSS3BucketProvider extends AWSEntityProvider {
if (bucket.Name) {
const bucketArn = `arn:aws:s3:::${bucket.Name}`;
const consoleLink = new ARN(bucketArn).consoleLink;
const tagsResponse = await s3.getBucketTagging({ Bucket: bucket.Name });
const tags = tagsResponse?.TagSet ?? [];
let tags: Tag[] = [];
try {
const tagsResponse = await s3.getBucketTagging({
Bucket: bucket.Name,
});
tags = tagsResponse?.TagSet ?? [];
} catch (e) {
this.logger.debug('No tags found for bucket', {
bucket: bucket.Name,
});
}
const resource: ResourceEntity = {
kind: 'Resource',
apiVersion: 'backstage.io/v1beta1',
Expand Down

0 comments on commit 4fa0b2c

Please sign in to comment.