LoginSignup
37
26

More than 5 years have passed since last update.

CloudFormationでクソが!って叫んだこと

Last updated at Posted at 2014-09-03

CloudFormation のテンプレートを書いてる時に、おや?と思ったことをまとめてみた。
タンツボみたいな記事になればいいなと思う。

SNS

MobilePush の PlatformApplication が作成できない

でも、これはしょうがない気もする。
特にAPNs。

DynamoDB

テーブル作成後にそのARNを取得できない

IAMロールとか作りたいのに Ref で取得できない。
仕方ないので自力で作成した。

{
  "Fn::Join" : [ "", [ "arn:aws:dynamodb:", {
    "Ref" : "AWS::Region"
  }, ":", {
    "Ref" : "AWS::AccountId"
  }, ":table/", {
    "Ref" : "DynamoDBTable"
  } ] ]
}

5年前の投稿。
[AWS Developer Forums] Request: Provide DynamoDB table ARN as attribute in CloudFormation

ElastiCache

memcachedクラスターをAZまたぎで作れない

まだ対応してないだけで、すぐ対応してくれるはず。

[AWS Developer Forums] Create ElastiCache cluster that spans multiple AZs?

リソース名のルールがおかしい

他のAWSサービスでリソースを作成した場合、だいたい スタック名-リソースID-英数字 となるのに ElastiCache はそうはならない。
cache-Cache-XX00XX0XXX00 とかなっちゃう。
まだ CacheParameterGroup しか試してないのでなんとも言えないけれども。

CacheParameterGroup の Properties が必須じゃない

ドキュメントには Required: Yes と書いてあるが、なくても作成できた。
値はすべてデフォルトになると思う。

{
  "ParameterGroup" : {
    "Type" : "AWS::ElastiCache::ParameterGroup",
    "Properties" : {
      "CacheParameterGroupFamily" : "memcached1.4",
      "Description" : "test"
    }
  }
}

PreferredMaintenanceWindow のフォーマットがドキュメントに載ってない

tue:19:00-tue:20:00 のように UTC で指定する。
曜日はこう。 sun|mon|tue|wed|thu|fri|sat

CloudFormation

子スタックの Parameters には CommaDelimitedList を渡せない

StringNumber しか渡せない。
エラーメッセージが Value of property Parameters must be an object なので非常にわかりにくい。

Note

If you use the ref function to pass a parameter value to a nested stack, comma-delimited list parameters must be of type String. In other words, you cannot pass values that are of type CommaDelimitedList to nested stacks.

解決策。
CommaDelimitedListFn::Join でカンマ区切りの String に変換すれば渡せる。
子スタックで再びリストに変換される。

{
  "SubStack" : {
    "Type" : "AWS::CloudFormation::Stack",
    "Properties" : {
      "TemplateURL" : "https://s3.amazonaws.com/cf/substack.template",
      "Parameters" : {
        "SubnetIds" : {"Fn::Join" : [ ",", { "Ref" : "SubnetIds" }] }
      }
    }
  }
}

List Params and Nested Stacks on CloudFormation

S3

旧バージョンの有効期限を設定ができない

S3のバージョニングを有効にしている場合、旧バージョンの有効期限を設定できない。
S3のAPIには設定方法(NoncurrentVersionExpiration)があるがCloudFormationが対応していない。

PUT Bucket lifecycle

現バージョンしか設定できない
{
  "Bucket" : {
    "Type" : "AWS::S3::Bucket",
    "Properties" : {
      "LifecycleConfiguration" : {
        "Rules" : [
          {
            "Status" : "Enabled",
            "ExpirationInDays" : 90
          }
        ]
      }
    }
  }
}
37
26
1

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
37
26