LoginSignup
23
19

More than 5 years have passed since last update.

aws cloudformation package コマンドで自動的にS3にアップロードしてくれるリソース一覧

Last updated at Posted at 2017-12-22

SAMでの利用がメインとなるaws cloudformation packageコマンドですが、実は他にも色々なリソースをS3に自動アップロードしてくれます。

すぐ忘れてしまうので自分用メモということで以下にまとめておきます。

TL;DR

aws cloudformation package便利!

対称読者

CloudFormationを利用してテンプレート以外のリソースをデプロイしている(したい)人

何ができる?

aws cloudformation packageコマンドを利用するとテンプレート外のリソース(プログラムコード、ネストしているテンプレート、Swagger定義ファイル)をアップロードしてくれる

対応表

Type Property Zip
AWS::Serverless::Function CodeUri true
AWS::Serverless::Api DefinitionUri false
AWS::ApiGateway::RestApi BodyS3Location false
AWS::Lambda::Function Code true
AWS::ElasticBeanstalk::ApplicationVersion SourceBundle true
AWS::CloudFormation::Stack TemplateURL false

Type: CloudFormationテンプレートのリソースのタイプ
Property: CloudFormationテンプレートの対象タイプのプロパティ名
Zip: アップロード時にzip圧縮するかどうか

以下のようにテンプレートからの相対パスで記述する

template.yml
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: The AWS CloudFormation template for BSE Workflow
Resources:
    MyLambdaFunction:
        Type: AWS::Serverless::Function
        Properties:
            CodeUri: ./code
            ...

$ aws cloudformation package \
    --s3-bucket [BucketName] \
    --s3-prefix [Prefix] \
    --template-file template.yml \
    --output-template-file .template.yml
$ cat .template.yml
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: The AWS CloudFormation template for BSE Workflow
Resources:
    MyLambdaFunction:
        Type: AWS::Serverless::Function
        Properties:
            CodeUri: s3://[BucketName]/[Prefix]/[ファイルのハッシュ値]
            ...

※ --s3-prefixを指定しない場合はトップレベルにアップロードされる
※ --output-template-fileを指定しない場合は標準出力に出力される

参考

23
19
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
23
19