kumogata-template 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0b3009b60eaa96c62f0e6cfcb8b5e93453e19a5
4
- data.tar.gz: f4cfbdffa75b3855c1aa1f49d7c5f3d032d56331
3
+ metadata.gz: 5d77897dbe21b5c2c2fb62d6483eb5cfdf798467
4
+ data.tar.gz: 34567d941237cd2d1a9bc488c8cb40f546f33339
5
5
  SHA512:
6
- metadata.gz: 8461e8ea61c6a49d1ec819213056ee32a89457da7dff59a1127fe5a8d97351d833084a3242cea845f6b4f507e50085db2650bce8ccb619e176c56b6adb85f97d
7
- data.tar.gz: 5ede82ac1c09eecb65d379251dd575ccc3ad8da3dd010f8de1c256424a05d53c158d7e9eb4fe53560ab88aba0db5a62c666b8eff63d73e5e2cac23204b4df57a
6
+ metadata.gz: 29aa4fd100a68042037ccfc18109616d4f1069b246cf8e178edd9a9ed11df0813106016f24a9a1b8e59970156415dd2cb8d6d596620ab93217e3545d5c16db03
7
+ data.tar.gz: 0f20034b16d11c2045608d0b238c584832eb048d59d2e84e013189fc4dedc03e6ffcfa0fdf494412aea176d304b24ebe9e580e3f1587d27120ef6f06ce8852b7
data/Gemfile.lock CHANGED
@@ -1,19 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kumogata-template (0.0.5)
4
+ kumogata-template (0.0.6)
5
5
  aws-sdk (~> 2.3)
6
6
  kumogata (= 0.5.10)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- aws-sdk (2.5.5)
12
- aws-sdk-resources (= 2.5.5)
13
- aws-sdk-core (2.5.5)
11
+ aws-sdk (2.5.6)
12
+ aws-sdk-resources (= 2.5.6)
13
+ aws-sdk-core (2.5.6)
14
14
  jmespath (~> 1.0)
15
- aws-sdk-resources (2.5.5)
16
- aws-sdk-core (= 2.5.5)
15
+ aws-sdk-resources (2.5.6)
16
+ aws-sdk-core (= 2.5.6)
17
17
  aws-sdk-v1 (1.66.0)
18
18
  json (~> 1.4)
19
19
  nokogiri (>= 1.4.4)
@@ -4,6 +4,7 @@
4
4
 
5
5
  AWS_REGION = {
6
6
  virginia: "us-east-1",
7
+ ohio: "us-east-2",
7
8
  oregon: "us-west-2",
8
9
  california: "us-west-1",
9
10
  ireland: "eu-west-1",
@@ -46,7 +47,7 @@ EC2_DEFAULT_IMAGE = "amazon linux official"
46
47
  # https://aws.amazon.com/ec2/pricing/
47
48
  EC2_INSTANCE_TYPES =
48
49
  [
49
- # Model vCPU CPU Credits/hour Mem(GiB) Storage
50
+ # Model vCPU CPU(Credits/hour) Mem(GiB) Storage
50
51
  # t2.nano 1 3 0.5 EBS-Only
51
52
  # t2.micro 1 6 1 EBS-Only
52
53
  # t2.small 1 12 2 EBS-Only
@@ -54,15 +55,16 @@ EC2_INSTANCE_TYPES =
54
55
  # t2.large 2 36 8 EBS-Only
55
56
  "t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large",
56
57
 
57
- # Model vCPU Mem(GiB) Storage Dedicated EBS Throughput(Mbps)
58
- # m4.large 2 8 EBS-only 450
59
- # m4.xlarge 4 16 EBS-only 750
60
- # m4.2xlarge 8 32 EBS-only 1,000
61
- # m4.4xlarge 16 64 EBS-only 2,000
62
- # m4.10xlarge 40 160 EBS-only 4,000
63
- "m4.large", "m4.xlarge", "m4.2xlarge", "m4.4xlarge", "m4.10xlarge",
58
+ # Model vCPU Mem(GiB) Storage Network EBS(Mbps)
59
+ # m4.large 2 8 EBS-only Moderate 450
60
+ # m4.xlarge 4 16 EBS-only High 750
61
+ # m4.2xlarge 8 32 EBS-only High 1,000
62
+ # m4.4xlarge 16 64 EBS-only High 2,000
63
+ # m4.10xlarge 40 160 EBS-only 10Gps 4,000
64
+ # m4.16xlarge 64 256 EBS Only 20Gps 10,000
65
+ "m4.large", "m4.xlarge", "m4.2xlarge", "m4.4xlarge", "m4.10xlarge", "m4.16xlarge",
64
66
 
65
- # Model vCPU Mem(GiB) Storage Dedicated EBS Throughput(Mbps)
67
+ # Model vCPU Mem(GiB) Storage EBS(Mbps)
66
68
  # c4.large 2 3.75 EBS-Only 500
67
69
  # c4.xlarge 4 7.5 EBS-Only 750
68
70
  # c4.2xlarge 8 15 EBS-Only 1,000
@@ -70,7 +72,7 @@ EC2_INSTANCE_TYPES =
70
72
  # c4.8xlarge 36 60 EBS-Only 4,000
71
73
  "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge",
72
74
 
73
- # Model vCPU Mem(GiB) SSD Storage (GB)
75
+ # Model vCPU Mem(GiB) SSD Storage(GB)
74
76
  # r3.large 2 15.25 1 x 32
75
77
  # r3.xlarge 4 30.5 1 x 80
76
78
  # r3.2xlarge 8 61 1 x 160
@@ -78,16 +80,17 @@ EC2_INSTANCE_TYPES =
78
80
  # r3.8xlarge 32 244 2 x 320
79
81
  "r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge",
80
82
 
81
- # Model vCPU Mem (GiB) SSD Storage (GB)
82
- # i2.xlarge 4 30.5 1 x 800
83
- # i2.2xlarge 8 61 2 x 800
84
- # i2.4xlarge 16 122 4 x 800
85
- # i2.8xlarge 32 244 8 x 800
83
+ # Model vCPU Mem(GiB) SSD Storage(GB)
84
+ # i2.xlarge 4 30.5 1 x 800
85
+ # i2.2xlarge 8 61 2 x 800
86
+ # i2.4xlarge 16 122 4 x 800
87
+ # i2.8xlarge 32 244 8 x 800
86
88
  "i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge",
87
89
 
88
- # Model vCPU Mem (GiB) SSD Storage (GB) network Bandwidth
89
- # x1.32xlargee 128 1,952 2 x 1,902 SSD 10 Gbps 10 Gbps
90
- "x1.32xlarge",
90
+ # Model vCPU Mem(GiB) Storage(GB) Network(Gbps)
91
+ # x1.16xlarge 64 174.5 1 x 1,920 SSD 10
92
+ # x1.32xlarge 128 1,952 2 x 1,902 SSD 10
93
+ "x1.16xlarge", "x1.32xlarge",
91
94
  ]
92
95
  EC2_DEFAULT_INSTANCE_TYPE = "t2.medium"
93
96
 
@@ -7,15 +7,23 @@ def _lambda_function_code(args)
7
7
  return "" unless args.key? :code
8
8
 
9
9
  code = args[:code]
10
- s3_bucket = code[:s3_bucket]
11
- s3_key = code[:s3_key]
10
+ is_s3 = (code.key? :zip_file) ? false : true
11
+ s3_bucket = code[:s3_bucket] || ""
12
+ s3_key = code[:s3_key] || ""
12
13
  s3_object_version = code[:s3_object_version] || ""
14
+ zip_file = code[:zip_file] || ""
15
+ unless zip_file.empty?
16
+ zip_file_code = []
17
+ File.foreach(zip_file) do |file|
18
+ file.each_line.collect{|line| zip_file_code << line.chomp }
19
+ end
20
+ end
13
21
 
14
22
  _{
15
- S3Bucket s3_bucket
16
- S3Key s3_key
17
- S3ObjectVersion s3_object_version unless s3_object_version.empty?
18
- #ZipFile
23
+ S3Bucket s3_bucket if is_s3
24
+ S3Key s3_key if is_s3
25
+ S3ObjectVersion s3_object_version if is_s3 and !s3_object_version.empty?
26
+ ZipFile _{ Fn__Join '\n', zip_file_code } unless is_s3
19
27
  }
20
28
  end
21
29
 
@@ -1 +1 @@
1
- KUMOGATA_TEMPLATE_VERSION = '0.0.6'
1
+ KUMOGATA_TEMPLATE_VERSION = '0.0.7'
@@ -9,12 +9,24 @@ name = _resource_name(args[:name], "lambda function")
9
9
  code = _lambda_function_code(args)
10
10
  description = args[:description] || ""
11
11
  function_name = args[:function_name] || ""
12
- handler = args[:handler]
12
+ runtime = _valid_values(args[:runtime],
13
+ %w( nodejs nodejs4.3 java8 python2.7 ), "python2.7")
14
+ handler =
15
+ if args.key? :handler
16
+ args[:handler]
17
+ else
18
+ case runtime
19
+ when /^nodejs.+/
20
+ "#{args[:function_name]}.handler"
21
+ when /^python.+/
22
+ "#{args[:function_name]}.lambda_handler"
23
+ else
24
+ args[:handler]
25
+ end
26
+ end
13
27
  memory_size = args[:memory_size] || 128
14
28
  role = _ref_attr_string("role", "Arn", args, "role")
15
29
  role = _ref_string("role_arn", args, "role") if role.empty?
16
- runtime = _valid_values(args[:runtime],
17
- %w( nodejs nodejs4.3 java8 python2.7 ), "python2.7")
18
30
  timeout = args[:timeout] || 3
19
31
  vpc_config = _lambda_vpc_config(args)
20
32
 
@@ -36,6 +36,7 @@ AWSRegionArch2AMIAmazonLinuxOfficial do
36
36
  end
37
37
 
38
38
  # CentOS 7 (x86_64) with Updates HVM
39
+ # https://wiki.centos.org/Cloud/AWS
39
40
  # https://aws.amazon.com/marketplace/ordering/ref=dtl_psb_continue?ie=UTF8&productId=b7ee8a69-ee97-4a49-9e68-afaee216db2e
40
41
  AWSRegionArch2AMICentos7Official do
41
42
  # 1602, released 02/26/2016
@@ -62,18 +63,18 @@ end
62
63
  # Ubuntu Server 16.04 LTS
63
64
  # https://cloud-images.ubuntu.com/locator/ec2/
64
65
  AWSRegionArch2AMIUbuntu16Official do
65
- # 16.04 LTS 20160420.3
66
+ # 16.04 LTS 20160907.1 hvm:ebs-ssd
66
67
  image_id = {
67
- virginia: "840910ee",
68
- oregon: "fa82739a",
69
- california: "fa82739a",
70
- frankfurt: "f0eb089f",
71
- ireland: "3079f543",
72
- singapore: "a5416cc6",
73
- sydney: "a5416cc6",
74
- tokyo: "3c5f4152",
75
- seoul: "a5416cc6",
76
- saopaulo: "567cf23a",
68
+ virginia: "2ef48339",
69
+ oregon: "746aba14",
70
+ california: "a9a8e4c9",
71
+ frankfurt: "a9a557c6",
72
+ ireland: "643d4217",
73
+ singapore: "42934921",
74
+ sydney: "623c0d01",
75
+ tokyo: "919cd68",
76
+ seoul: "", ## N/A
77
+ saopaulo: "60bd2d0c",
77
78
  }
78
79
 
79
80
  AWS_REGION.each do |key, region|
@@ -82,4 +83,3 @@ AWSRegionArch2AMIUbuntu16Official do
82
83
  end
83
84
  end
84
85
  end
85
-
@@ -0,0 +1,5 @@
1
+ #
2
+ # Output name
3
+ #
4
+
5
+ _output "#{args[:name]} name", ref_value: args[:name]
@@ -0,0 +1,4 @@
1
+ import boto3
2
+
3
+ def lambda_handler(event, context):
4
+ print('hello lambda')
data/test/lambda_test.rb CHANGED
@@ -13,6 +13,29 @@ Test _lambda_function_code(code: { s3_bucket: "test", s3_key: "test" })
13
13
  "S3Bucket": "test",
14
14
  "S3Key": "test"
15
15
  }
16
+ }
17
+ EOS
18
+ assert_equal exp_template.chomp, act_template
19
+
20
+ template = <<-EOS
21
+ Test _lambda_function_code(code: { zip_file: "test/data/lambda_function.py" })
22
+ EOS
23
+ act_template = run_client_as_json(template)
24
+ exp_template = <<-EOS
25
+ {
26
+ "Test": {
27
+ "ZipFile": {
28
+ "Fn::Join": [
29
+ "\\\\n",
30
+ [
31
+ "import boto3",
32
+ "",
33
+ "def lambda_handler(event, context):",
34
+ " print('hello lambda')"
35
+ ]
36
+ ]
37
+ }
38
+ }
16
39
  }
17
40
  EOS
18
41
  assert_equal exp_template.chomp, act_template
@@ -38,4 +61,3 @@ Test _lambda_vpc_config(vpc: { security_groups: [ "test" ], subnets: [ "test" ]
38
61
  assert_equal exp_template.chomp, act_template
39
62
  end
40
63
  end
41
-
@@ -3,7 +3,7 @@ require 'abstract_unit'
3
3
  class LambdaFunctionTest < Minitest::Test
4
4
  def test_normal
5
5
  template = <<-EOS
6
- _lambda_function "test", code: { s3_bucket: "test", s3_key: "test" }, handler: "test", ref_role: "test", runtime: "nodejs4.3"
6
+ _lambda_function "test", code: { s3_bucket: "test", s3_key: "test" }, function_name: "test", ref_role: "test", runtime: "nodejs4.3"
7
7
  EOS
8
8
  act_template = run_client_as_json(template)
9
9
  exp_template = <<-EOS
@@ -15,7 +15,8 @@ _lambda_function "test", code: { s3_bucket: "test", s3_key: "test" }, handler: "
15
15
  "S3Bucket": "test",
16
16
  "S3Key": "test"
17
17
  },
18
- "Handler": "test",
18
+ "FunctionName": "test",
19
+ "Handler": "test.handler",
19
20
  "MemorySize": "128",
20
21
  "Role": {
21
22
  "Fn::GetAtt": [
@@ -27,6 +28,45 @@ _lambda_function "test", code: { s3_bucket: "test", s3_key: "test" }, handler: "
27
28
  "Timeout": "3"
28
29
  }
29
30
  }
31
+ }
32
+ EOS
33
+ assert_equal exp_template.chomp, act_template
34
+
35
+ template = <<-EOS
36
+ _lambda_function "test", code: { zip_file: "test/data/lambda_function.py" }, function_name: "test", ref_role: "test", runtime: "python2.7"
37
+ EOS
38
+ act_template = run_client_as_json(template)
39
+ exp_template = <<-EOS
40
+ {
41
+ "TestLambdaFunction": {
42
+ "Type": "AWS::Lambda::Function",
43
+ "Properties": {
44
+ "Code": {
45
+ "ZipFile": {
46
+ "Fn::Join": [
47
+ "\\\\n",
48
+ [
49
+ "import boto3",
50
+ "",
51
+ "def lambda_handler(event, context):",
52
+ " print('hello lambda')"
53
+ ]
54
+ ]
55
+ }
56
+ },
57
+ "FunctionName": "test",
58
+ "Handler": "test.lambda_handler",
59
+ "MemorySize": "128",
60
+ "Role": {
61
+ "Fn::GetAtt": [
62
+ "TestRole",
63
+ "Arn"
64
+ ]
65
+ },
66
+ "Runtime": "python2.7",
67
+ "Timeout": "3"
68
+ }
69
+ }
30
70
  }
31
71
  EOS
32
72
  assert_equal exp_template.chomp, act_template
@@ -31,16 +31,16 @@ class MappingsEc2Test < Minitest::Test
31
31
  }
32
32
  centos7_images = get_image_values(centos7_image_id)
33
33
  ubuntu16_image_id = {
34
- virginia: "840910ee",
35
- oregon: "fa82739a",
36
- california: "fa82739a",
37
- frankfurt: "f0eb089f",
38
- ireland: "3079f543",
39
- singapore: "a5416cc6",
40
- sydney: "a5416cc6",
41
- tokyo: "3c5f4152",
42
- seoul: "a5416cc6",
43
- saopaulo: "567cf23a",
34
+ virginia: "2ef48339",
35
+ oregon: "746aba14",
36
+ california: "a9a8e4c9",
37
+ frankfurt: "a9a557c6",
38
+ ireland: "643d4217",
39
+ singapore: "42934921",
40
+ sydney: "623c0d01",
41
+ tokyo: "919cd68",
42
+ seoul: "", ## N/A
43
+ saopaulo: "60bd2d0c",
44
44
  }
45
45
  ubuntu16_images = get_image_values(ubuntu16_image_id)
46
46
 
@@ -1,6 +1,6 @@
1
1
  require 'abstract_unit'
2
2
 
3
- class OutputUserTest < Minitest::Test
3
+ class OutputArnTest < Minitest::Test
4
4
  def test_normal
5
5
  template = <<-EOS
6
6
  _output_arn "test"
@@ -0,0 +1,21 @@
1
+ require 'abstract_unit'
2
+
3
+ class OutputNameTest < Minitest::Test
4
+ def test_normal
5
+ template = <<-EOS
6
+ _output_name "test"
7
+ EOS
8
+ act_template = run_client_as_json(template)
9
+ exp_template = <<-EOS
10
+ {
11
+ "TestName": {
12
+ "Description": "description of TestName",
13
+ "Value": {
14
+ "Ref": "Test"
15
+ }
16
+ }
17
+ }
18
+ EOS
19
+ assert_equal exp_template.chomp, act_template
20
+ end
21
+ end
@@ -1,6 +1,6 @@
1
1
  require 'abstract_unit'
2
2
 
3
- class OutputUserTest < Minitest::Test
3
+ class OutputRdsrTest < Minitest::Test
4
4
  def test_normal
5
5
  template = <<-EOS
6
6
  _output_rds "test"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata-template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoya Nakazawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2016-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -199,6 +199,7 @@ files:
199
199
  - template/output-elasticache.rb
200
200
  - template/output-elb.rb
201
201
  - template/output-emr.rb
202
+ - template/output-name.rb
202
203
  - template/output-rds.rb
203
204
  - template/output-redshift.rb
204
205
  - template/output-s3.rb
@@ -231,6 +232,7 @@ files:
231
232
  - test/alb_test.rb
232
233
  - test/autoscaling_test.rb
233
234
  - test/codedeploy_test.rb
235
+ - test/data/lambda_function.py
234
236
  - test/datapipeline_test.rb
235
237
  - test/dynamodb_test.rb
236
238
  - test/ec2_test.rb
@@ -322,6 +324,7 @@ files:
322
324
  - test/template/output-elasticache_test.rb
323
325
  - test/template/output-elb_test.rb
324
326
  - test/template/output-emr_test.rb
327
+ - test/template/output-name_test.rb
325
328
  - test/template/output-rds_test.rb
326
329
  - test/template/output-redshift_test.rb
327
330
  - test/template/output-s3_test.rb
@@ -379,6 +382,7 @@ test_files:
379
382
  - test/alb_test.rb
380
383
  - test/autoscaling_test.rb
381
384
  - test/codedeploy_test.rb
385
+ - test/data/lambda_function.py
382
386
  - test/datapipeline_test.rb
383
387
  - test/dynamodb_test.rb
384
388
  - test/ec2_test.rb
@@ -470,6 +474,7 @@ test_files:
470
474
  - test/template/output-elasticache_test.rb
471
475
  - test/template/output-elb_test.rb
472
476
  - test/template/output-emr_test.rb
477
+ - test/template/output-name_test.rb
473
478
  - test/template/output-rds_test.rb
474
479
  - test/template/output-redshift_test.rb
475
480
  - test/template/output-s3_test.rb