2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CloudFormationでS3バケットを作成しようとしたら「Error Code: 400 Bad Request」となる

Posted at

事象

demo.yml
Parameters:
  bucketName:
    Type: String

Resources:
  Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub $bucketName

AWS CLIでcreate-stackコマンドにより上記テンプレートdemo.ymlをもとにS3バケットを作成しようとした。

$ aws cloudformation create-stack \
  --stack-name demoStack \
  --template-body file://demo.yml \
  --parameters ParameterKey=bucketName,ParameterValue=$bucket_name

しかし下記のようにError Code: 400 Bad Requestによりバケットの作成でCREATE_FAILEDとなりスタック作成がロールバックしてしまう。

image.png

Bad Request (Service: Amazon S3; Status Code: 400; Error Code: 400 Bad Request; Request ID: 82FD2F03945D2983; S3 Extended Request ID: 5keeRc+W8kea1g+S7tWqhXfeXvv+Fs9mhQnu5zlfiiWT1u2O86HFjP54qYiq4/hvcA1yw1M1hxY=)

解決

BucketNameでのParametersの指定の仕方が誤っていることが原因だった。

  • 誤:!Sub $bucketName
  • 正:!Sub ${bucketName} または !Ref bucketName
modified-demo.yml
Parameters:
  bucketName:
    Type: String

Resources:
  Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref bucketName

上記の修正後のテンプレートmodified-demo.ymlであればS3バケットを正常に作成することができた。

image.png

以上

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?