{"id":19407,"date":"2018-12-07T09:00:44","date_gmt":"2018-12-07T00:00:44","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=19407"},"modified":"2018-12-03T10:20:03","modified_gmt":"2018-12-03T01:20:03","slug":"aws-sam-tips","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2018\/12\/07\/aws-sam-tips\/","title":{"rendered":"\u77e5\u3063\u3066\u304a\u304d\u305f\u304b\u3063\u305fAWS SAM \u306e\u5c0f\u30cd\u30bf4\u9078"},"content":{"rendered":"

\u3053\u308c\u306f TECHSCORE Advent Calendar 2018<\/a> \u306e7\u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n

\u3053\u3093\u306b\u3061\u306f\u3001\u571f\u5c4b\u3067\u3059\u3002
\n\u4eca\u5e741\u6708\u306b
AWS Lambda \u304c Go \u306e\u30b5\u30dd\u30fc\u30c8\u3092\u958b\u59cb<\/a>\u3057\u307e\u3057\u305f\u306d\u3002
\nGopher \u305f\u3061\u304c\u8cd1\u308f\u3046\u4e2d\u3001\u79c1\u3082 Go \u306e\u30a2\u30d7\u30ea\u3092 Lambda \u3067\u4f5c\u308a\u305f\u3044\u306a\u3042\u3068\u601d\u3044\u3001
AWS SAM<\/a>\u3092\u4f7f\u3063\u3066\u74b0\u5883\u69cb\u7bc9\u3092\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n

\u74b0\u5883\u69cb\u7bc9\u306f\u30c1\u30e3\u30c1\u30e3\u30c3\u3068\u7d42\u308f\u3089\u305b\u305f\u3044\uff01\u3068\u601d\u3044\u3064\u3064\u3082\u3001\u5b9f\u969b\u306bSAM\u3092\u4f7f\u3063\u3066\u307f\u308b\u3068\u3001\u81ea\u5206\u304c\u3084\u308a\u305f\u3044\u3053\u3068\u3092\u5b9f\u73fe\u3059\u308b\u65b9\u6cd5\u304c\u308f\u304b\u3089\u305a\u3001\u8abf\u3079\u308b\u306e\u306b\u610f\u5916\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n

\u305d\u3053\u3067\u4eca\u56de\u306f\u300c\u5148\u306b\u77e5\u3063\u3066\u308c\u3070\u3082\u3063\u3068\u5de5\u6570\u524a\u6e1b\u3067\u304d\u305f\u306a\u30fc\u300d\u3068\u601d\u3063\u305f\u3001AWS SAM \u306b\u95a2\u3059\u308b\u5c0f\u30cd\u30bf\u30924\u3064\u3092\u307e\u3068\u3081\u307e\u3057\u305f\u3002<\/p>\n

\u203bAWS SAM \u306f\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e Benefits of Using AWS SAM<\/a> \u306b\u66f8\u304b\u308c\u3066\u3044\u308b\u901a\u308a\u3001AWS CloudFormation \u306e\u62e1\u5f35\u3067\u3059\u3002\u672c\u8a18\u4e8b\u306e\u5185\u5bb9\u306f\u3001CloudFormation \u306b\u3082\u5f53\u3066\u306f\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

1. \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5185\u3067\u74b0\u5883\u3054\u3068\u306b\u7570\u306a\u308b\u5024\u3092\u6e21\u3057\u305f\u3044<\/h2>\n

\u958b\u767a\u74b0\u5883\u3068\u672c\u756a\u74b0\u5883\u306f\u3067\u304d\u308b\u3060\u3051\u540c\u3058\u6761\u4ef6\u306b\u3057\u305f\u3044\u3082\u306e\u3067\u3059\u304c\u3001\u3069\u3046\u3057\u3066\u3082\u74b0\u5883\u3054\u3068\u306b\u7570\u306a\u308b\u5024\u3092\u6e21\u3057\u305f\u3044\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3088\u306d\u3002
\n\u300c\u74b0\u5883\u3054\u3068\u306b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308b\uff01\u300d\u3068\u3044\u3046\u65b9\u6cd5\u3067\u3082\u89e3\u6c7a\u3067\u304d\u307e\u3059\u304c\u3001\u307b\u307c\u540c\u3058\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u3044\u304f\u3064\u3082\u7ba1\u7406\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3057\u3001\u958b\u767a\u74b0\u5883\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u884c\u3063\u305f\u5909\u66f4\u3092\u672c\u756a\u74b0\u5883\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u53cd\u6620\u3057\u5fd8\u308c\u3066\u3044\u305f...\u306a\u3069\u306e\u30ea\u30b9\u30af\u3092\u8003\u3048\u308b\u3068\u3042\u307e\u308a\u5b09\u3057\u304f\u306a\u3044\u3067\u3059\u3002
\n\u305d\u3093\u306a\u6642\u306f
Parameters<\/a> \u3068 Mappings<\/a> \u3092\u4f7f\u3046\u3068\u4fbf\u5229\u3067\u3059\u3002<\/p>\n

\u3056\u3063\u304f\u308a\u3068\u3057\u305f\u4f7f\u3044\u65b9\u306f<\/p>\n

    \n
  1. Parameters \u3067\u74b0\u5883\u306e\u30ea\u30b9\u30c8\u3092\u4f5c\u6210<\/li>\n
  2. Mappings \u3067\u30ea\u30b9\u30c8\u3054\u3068\u306b\u30de\u30c3\u30d7\u3092\u5b9a\u7fa9<\/li>\n
  3. \u30de\u30c3\u30d7\u306e\u5024\u3092\u4f7f\u3044\u305f\u3044\u7b87\u6240\u3067\u57cb\u3081\u8fbc\u307f<\/li>\n
  4. \u74b0\u5883\u3092\u6307\u5b9a\u3057\u3066\u30c7\u30d7\u30ed\u30a4<\/li>\n<\/ol>\n

    \u3068\u3044\u3046\u6d41\u308c\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

    \u4f8b\u3068\u3057\u3066\u74b0\u5883\u3054\u3068\u306b\u7570\u306a\u308b\u30a2\u30e9\u30fc\u30c8\u306e\u901a\u77e5\u5148\u3092 SNS \u306b\u8a2d\u5b9a\u3057\u3066\u307f\u307e\u3059\u3002
    \n\u307e\u305a Parameters \u3092\u4f7f\u3063\u305f\u74b0\u5883\u306e\u30ea\u30b9\u30c8\u306f\u6b21\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u958b\u767a\u74b0\u5883\u3001\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u74b0\u5883\u3001\u672c\u756a\u74b0\u5883\u3092\u7528\u610f\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n

    \nParameters:\n Environment:\n   Type: String\n   AllowedValues:\n   - development # \u958b\u767a\u74b0\u5883\n   - staging # \u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u74b0\u5883\n   - production # \u672c\u756a\u74b0\u5883\n   Default: development\n<\/pre>\n

    Mappings \u306f\u6b21\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u74b0\u5883\u3054\u3068\u306b\u901a\u77e5\u5148\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n

    \nMappings:\n EnvironmentMap:\n   development:\n     alertEndpoint: 'development@example.com'\n   staging:\n     alertEndpoint: 'staging@example.com'\n   production:\n     alertEndpoint: 'production@example.com'\n<\/pre>\n

    \u4f7f\u3044\u305f\u3044\u7b87\u6240\u306b FindInMap<\/a> \u3092\u4f7f\u3063\u3066\u5024\u3092\u57cb\u3081\u8fbc\u307f\u307e\u3059\u3002\u3053\u3053\u3067\u306f SNS \u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3068\u3057\u3066\u3001\u30a2\u30e9\u30fc\u30c8\u5148\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n

    \nResources:\n  SampleNotice: \n    Type: \"AWS::SNS::Topic\"\n    Properties:\n      # DisplayName \u306a\u3069\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u7701\u7565\n      Subscription:\n      - Endpoint: !FindInMap [ EnvironmentMap, !Ref Environment, alertEndpoint] # \u3053\u3053\n        Protocol: email\n<\/pre>\n

    \u3042\u3068\u306f\u30c7\u30d7\u30ed\u30a4\u6642\u306b --parameter-overrides<\/a> \u3092\u4f7f\u3063\u3066\u74b0\u5883\u3092\u6307\u5b9a\u3059\u308c\u3070OK\u3067\u3059\u3002<\/p>\n

    \n# cloudformation\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u81ea\u52d5\u751f\u6210\n$ aws cloudformation package \\\n    --template-file template.yml \\\n    --s3-bucket sample \\\n    --s3-prefix sample \\\n    --output-template-file packaged_template.yml\n\n# \u30c7\u30d7\u30ed\u30a4\n$ aws cloudformation deploy \\\n   --template-file packaged_template.yml \\ \n   --stack-name sample \\\n   --capabilities CAPABILITY_IAM \\\n   --parameter-overrides Environment=development # \u3053\u3053\n<\/pre>\n

    2. \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5185\u3067AWS\u306e\u30a2\u30ab\u30a6\u30f3\u30c8ID\u3092\u57cb\u3081\u8fbc\u307f\u305f\u3044<\/h2>\n

    \u74b0\u5883\u3054\u3068\u306bAWS\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u4f5c\u6210\u3057\u3066\u30011\u3064\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u3067\u7ba1\u7406\u3057\u305f\u3044\u6642\u3001\u30b5\u30fc\u30d3\u30b9\u306e\u540d\u524d\u3092\u540c\u3058\u306b\u3057\u3066\u304a\u3051\u3070\u3001AWS\u306e\u30a2\u30ab\u30a6\u30f3\u30c8ID\u3092\u5909\u66f4\u3059\u308b\u3060\u3051\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

    \u4f8b\uff09 A\u3068B\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u305d\u308c\u305e\u308c sample.fifo \u3068\u3044\u3046\u540d\u524d\u306eSQS\u3092\u5b9a\u7fa9\u3057\u305f\u5834\u5408<\/p>\n