Skip to content

Commit

Permalink
fix CI failure
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronZyLee committed Mar 8, 2024
1 parent c2279ea commit 3e5fe03
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
55 changes: 47 additions & 8 deletions packages/amplify-codegen-e2e-tests/src/cleanup-e2e-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type AmplifyAppInfo = {

type S3BucketInfo = {
name: string;
region: string;
jobId?: string;
cbInfo?: CodeBuild.Build;
};
Expand Down Expand Up @@ -118,7 +119,16 @@ const getOrphanS3TestBuckets = async (account: AWSAccountInfo): Promise<S3Bucket
const s3Client = new aws.S3(getAWSConfig(account));
const listBucketResponse = await s3Client.listBuckets().promise();
const staleBuckets = listBucketResponse.Buckets.filter(testBucketStalenessFilter);
return staleBuckets.map(it => ({ name: it.Name }));
const bucketInfos = await Promise.all(
staleBuckets.map(async (staleBucket): Promise<S3BucketInfo> => {
const region = await getBucketRegion(account, staleBucket.Name);
return {
name: staleBucket.Name,
region,
};
}),
);
return bucketInfos;
};

/**
Expand Down Expand Up @@ -276,27 +286,52 @@ const getJobCodeBuildDetails = async (jobIds: string[]): Promise<CodeBuild.Build
}
};

const getBucketRegion = async (account: AWSAccountInfo, bucketName: string): Promise<string> => {
const awsConfig = getAWSConfig(account);
const s3Client = new aws.S3(awsConfig);
const location = await s3Client.getBucketLocation({ Bucket: bucketName }).promise();
const region = location.LocationConstraint ?? 'us-east-1';
return region;
};

const getS3Buckets = async (account: AWSAccountInfo): Promise<S3BucketInfo[]> => {
const s3Client = new aws.S3(getAWSConfig(account));
const awsConfig = getAWSConfig(account);
const s3Client = new aws.S3(awsConfig);
const buckets = await s3Client.listBuckets().promise();
const result: S3BucketInfo[] = [];
for (const bucket of buckets.Buckets) {
let region: string | undefined;
try {
region = await getBucketRegion(account, bucket.Name);
// Operations on buckets created in opt-in regions appear to require region-specific clients
const regionalizedClient = new aws.S3({
region,
...(awsConfig as object),
});
const bucketDetails = await s3Client.getBucketTagging({ Bucket: bucket.Name }).promise();
const jobId = getJobId(bucketDetails.TagSet);
if (jobId) {
result.push({
name: bucket.Name,
region,
jobId
});
}
} catch (e) {
if (e.code !== 'NoSuchTagSet' && e.code !== 'NoSuchBucket') {
// TODO: Why do we process the bucket even with these particular errors?
if (e.code === 'NoSuchTagSet' || e.code === 'NoSuchBucket') {
result.push({
name: bucket.Name,
region: region ?? 'us-east-1',
});
} else if (e.code === 'InvalidToken') {
// We see some buckets in some accounts that were somehow created in an opt-in region different from the one to which the account is
// actually opted in. We don't quite know how this happened, but for now, we'll make a note of the inconsistency and continue
// processing the rest of the buckets.
console.error(`Skipping processing ${account.accountId}, bucket ${bucket.Name}`, e);
} else {
throw e;
}
result.push({
name: bucket.Name,
});
}
}
return result;
Expand Down Expand Up @@ -516,8 +551,12 @@ const deleteBucket = async (account: AWSAccountInfo, accountIndex: number, bucke
const { name } = bucket;
try {
console.log(`${generateAccountInfo(account, accountIndex)} Deleting S3 Bucket ${name}`);
const s3 = new aws.S3(getAWSConfig(account));
await deleteS3Bucket(name, s3);
const awsConfig = getAWSConfig(account);
const regionalizedS3Client = new aws.S3({
region: bucket.region,
...(awsConfig as object),
});
await deleteS3Bucket(name, regionalizedS3Client);
} catch (e) {
console.log(`${generateAccountInfo(account, accountIndex)} Deleting bucket ${name} failed with error ${e.message}`);
if (e.code === 'ExpiredTokenException') {
Expand Down
12 changes: 12 additions & 0 deletions packages/appsync-modelgen-plugin/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ export type FieldType = 'ID' | 'String' | 'Int' | 'Float' | 'AWSDate' | 'AWSTime
model: string;
} | {
nonModel: string;
} | {
input: string;
};

// @public (undocumented)
export type Input = {
name: string;
arguments: Arguments;
};

// @public (undocumented)
Expand All @@ -119,6 +127,7 @@ export type ModelIntrospectionSchema = {
queries?: SchemaQueries;
mutations?: SchemaMutations;
subscriptions?: SchemaSubscriptions;
inputs?: SchemaInputs;
};

// Warning: (ae-forgotten-export) The symbol "RawAppSyncModelConfig" needs to be exported by the entry point index.d.ts
Expand All @@ -145,6 +154,9 @@ export type SchemaEnum = {
// @public (undocumented)
export type SchemaEnums = Record<string, SchemaEnum>;

// @public (undocumented)
export type SchemaInputs = Record<string, Input>;

// @public (undocumented)
export type SchemaModel = {
name: string;
Expand Down

0 comments on commit 3e5fe03

Please sign in to comment.