Skip to content

Commit

Permalink
fix: look up bucket region for large templates
Browse files Browse the repository at this point in the history
  • Loading branch information
OlafConijn committed Dec 4, 2023
1 parent e1f5f80 commit 4860a81
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-organization-formation",
"version": "1.0.12-beta.4",
"version": "1.0.12-beta.6",
"description": "Infrastructure as code solution for AWS Organizations",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 4 additions & 2 deletions src/util/aws-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { fromEnv, fromTemporaryCredentials } from '@aws-sdk/credential-providers
import { DescribeOrganizationCommand, DescribeOrganizationCommandOutput, OrganizationsClient, OrganizationsClientConfig } from '@aws-sdk/client-organizations';
import { DescribeRegionsCommand, EC2Client, EC2ClientConfig } from '@aws-sdk/client-ec2';
import { GetCallerIdentityCommand, STSClient } from '@aws-sdk/client-sts';
import { BucketLocationConstraint, CreateBucketCommand, CreateBucketCommandInput, DeleteObjectCommand, PutBucketEncryptionCommand, PutBucketOwnershipControlsCommand, PutObjectCommand, PutObjectCommandInput, PutPublicAccessBlockCommand, S3Client, S3ClientConfig } from '@aws-sdk/client-s3';
import { BucketLocationConstraint, CreateBucketCommand, CreateBucketCommandInput, DeleteObjectCommand, GetBucketLocationCommand, PutBucketEncryptionCommand, PutBucketOwnershipControlsCommand, PutObjectCommand, PutObjectCommandInput, PutPublicAccessBlockCommand, S3Client, S3ClientConfig } from '@aws-sdk/client-s3';
import { CloudFormationClient, CreateStackCommandInput, UpdateStackCommandInput, ValidateTemplateCommandInput, DescribeStacksCommandOutput, UpdateStackCommand, waitUntilStackUpdateComplete, DescribeStacksCommand, CreateStackCommand, waitUntilStackCreateComplete, DeleteStackCommand, waitUntilStackDeleteComplete, paginateListExports, CloudFormationServiceException, CloudFormationClientConfig } from '@aws-sdk/client-cloudformation';
import { defaultProvider } from '@aws-sdk/credential-provider-node';
import { chain } from '@smithy/property-provider';
Expand Down Expand Up @@ -736,9 +736,11 @@ export class CfnUtil {
}
}
}
const largeTemplateBucketRegion = await s3Service.send(new GetBucketLocationCommand({ Bucket: bucketName }));
const bucketRegion: string = largeTemplateBucketRegion.LocationConstraint ?? 'us-east-1';
const putObjectRequest: PutObjectCommandInput = { Bucket: bucketName, Key: `${stackName}-${templateHash}.json`, Body: stackInput.TemplateBody, ACL: 'bucket-owner-full-control' };
await s3Service.send(new PutObjectCommand(putObjectRequest));
stackInput.TemplateURL = `https://${bucketName}.s3-${binding.region}.amazonaws.com/${putObjectRequest.Key}`;
stackInput.TemplateURL = `https://${bucketName}.s3.${bucketRegion}.amazonaws.com/${putObjectRequest.Key}`;
delete stackInput.TemplateBody;
}
}
Expand Down

0 comments on commit 4860a81

Please sign in to comment.