Below you will find pages that utilize the taxonomy term “stack”
Posts
Deploy s3 bucket by cloudformation - 進階版
開發系統時部分的程式碼會參考到基礎建設的名稱,例如:S3 bucket自動部署創建出來的名稱,或是需要利用aws resource arn去做trigger lambda事件的綁定,都需要輸出佈建後的結果。 { "AWSTemplateFormatVersion": "2010-09-09", "Description": "Create S3 bucket on AWS", "Parameters": { "StageName": { "Type": "String" } }, "Resources": { "S3Test": { "Type": "AWS::S3::Bucket", "Properties": { "BucketName": { "Fn::Sub": [ "paul-test-${StageName}", { "StageName": { "Ref": "StageName" } } ] }, "AccessControl": "PublicReadWrite", "CorsConfiguration": { "CorsRules": [ { "AllowedHeaders": [ "*" ], "AllowedMethods": [ "GET" ], "AllowedOrigins": [ "*" ], "ExposedHeaders": [ "Date" ], "Id": "myCORSRuleId1", "MaxAge": "3600" } ] } } } }, "Outputs": { "S3Test": { "Description": "Information about s3 bucket name", "Value": { "Fn::Sub": [ "paul-test-${StageName}", { "StageName": { "Ref": "StageName" } } ] }, "Export": { "Name": { "Fn::Sub": [ "${StackName}-S3Test-bucketname", { "StackName": { "Ref": "AWS::StackName" } } ] } } } } } Fn::Sub: 代表字串裡的變數,可用接下來的變數給取代。當字串不需要有變數取代時,可以簡單的利用{ "Fn::Sub" : String }描述即可。需要由變數替換的模板為{ "Fn::Sub" : [ String, { Var1Name: Var1Value, Var2Name: Var2Value } ] }。