Reputation: 1845
I have a yaml file to create a stack with CloudFormation. However when it comes to create some S3 buckets the script fails giving me a 400 Bad Request error in the console. I tried to run a script that does only this, but has the same result. This is the yaml file i'm using
AWSTemplateFormatVersion: 2010-09-09
Parameters:
ArtifactsBucket:
Type: String
Default: artifacts.bucket
Description: S3 Bucket Name for CodeBuild Artifacts
DevBucket:
Type: String
Default: dev.bucket
Description: S3 Bucket Name for Dev environment.
StagingBucket:
Type: String
Default: staging.bucket
Description: S3 Bucket Name for Staging environment
ProductionBucket:
Type: String
Default: production.bucket
Description: S3 Bucket Name for Production environment
Resources:
# S3 Bucket for build artifacts
BuildArtifactsBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: !Sub '${ArtifactsBucket}'
# S3 Bucket for Dev environment
DevS3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: !Sub '${DevBucket}'
# S3 Bucket for Staging environment
StagingS3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: !Sub '${StagingBucket}'
# S3 Bucket for Production environment
ProductionS3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: !Sub '${ProductionBucket}'
I really don't understand what is wrong with this, since if i left only one S3 Bucket resource it works
Upvotes: 2
Views: 1400
Reputation: 1805
It's entirely possible that you're hitting a throttle in the S3 control api.
To avoid excessive parallel requests, you can add a DependsOn
parameter to force the buckets to be created sequentially:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
ArtifactsBucket:
Type: String
Default: artifacts.bucket
Description: S3 Bucket Name for CodeBuild Artifacts
DevBucket:
Type: String
Default: dev.bucket
Description: S3 Bucket Name for Dev environment.
StagingBucket:
Type: String
Default: staging.bucket
Description: S3 Bucket Name for Staging environment
ProductionBucket:
Type: String
Default: production.bucket
Description: S3 Bucket Name for Production environment
Resources:
# S3 Bucket for build artifacts
BuildArtifactsBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: !Sub '${ArtifactsBucket}'
# S3 Bucket for Dev environment
DevS3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: !Sub '${DevBucket}'
DependsOn: "BuildArtifactsBucket"
# S3 Bucket for Staging environment
StagingS3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: !Sub '${StagingBucket}'
DependsOn: "DevS3Bucket"
# S3 Bucket for Production environment
ProductionS3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: !Sub '${ProductionBucket}'
DependsOn: "StagingS3Bucket"
Here all the buckets will be created sequentially. You may be able to batch them into a few groups instead of strictly one-at-a-time; experiment and see what works.
Upvotes: 4