sparse-intern-71089
03/15/2021, 7:09 PMwitty-candle-66007
03/15/2021, 7:54 PMaws.s3.getBucket()
function instead of using the get
method?
https://www.pulumi.com/docs/reference/pkg/aws/s3/getbucket/little-cartoon-10569
03/15/2021, 8:00 PMgetBucket
is the AWS SDK function, returning a GetBucketResult. It doesn't give a Pulumi Bucket object.millions-furniture-75402
03/15/2021, 8:35 PMaws.s3.Bucket.get(existingBucketId);
Implicitly creates a NEW bucket with another hash appendedlittle-cartoon-10569
03/15/2021, 8:37 PMmillions-furniture-75402
03/15/2021, 8:37 PMlittle-cartoon-10569
03/15/2021, 8:38 PMnew aws.s3.Bucket(..., { /* args */ }, { /* opts */ import: bucketName });
and manage it through Pulumi.millions-furniture-75402
03/15/2021, 8:39 PMlittle-cartoon-10569
03/15/2021, 8:41 PMmillions-furniture-75402
03/15/2021, 8:41 PMconst resourceList = await clients.s3.listBuckets()
.promise();
const service = {
resources: {},
};
resourceList.Buckets!.forEach(resource => {
const resourceName = resource.Name!.replace(/-[a-z0-9]{7}$/, "");
const resourceId = resource.Name;
// @ts-ignore
service.resources[resourceName] = aws.s3.Bucket.get(resourceName, resourceId);
millions-furniture-75402
03/15/2021, 8:42 PMlittle-cartoon-10569
03/15/2021, 8:43 PMmillions-furniture-75402
03/15/2021, 9:10 PMlittle-cartoon-10569
03/15/2021, 9:10 PMmillions-furniture-75402
03/15/2021, 9:14 PMmillions-furniture-75402
03/15/2021, 9:16 PMlittle-cartoon-10569
03/15/2021, 9:32 PMmillions-furniture-75402
03/16/2021, 1:06 PMmillions-furniture-75402
03/16/2021, 1:06 PMmillions-furniture-75402
03/16/2021, 4:17 PMawait Promise.all(resourceList.Buckets!.map(async resource => {
const resourceName = resource.Name!.replace(/-[a-f0-9]{7}$/, "");
const resourceId = resource.Name;
const bucketLocation = await clients.s3.getBucketLocation({ Bucket: resourceId! }).promise();
const bucketRegion = bucketLocation.LocationConstraint || "us-east-1";
if (bucketRegion === aws.config.region) {
service.resources[resourceName] = aws.s3.Bucket.get(resourceName, resourceId);
}
}));