1
1
// -*- coding: utf-8; mode: groovy -*-
2
-
3
- import com.amazonaws.services.lambda.model.InvocationType ;
4
-
5
- import jp.classmethod.aws.gradle.lambda.AWSLambdaDeleteFunctionTask ;
6
- import jp.classmethod.aws.gradle.lambda.AWSLambdaInvokeTask ;
7
- import jp.classmethod.aws.gradle.lambda.AWSLambdaMigrateFunctionTask ;
8
- import jp.classmethod.aws.gradle.lambda.AWSLambdaPublishVersionTask ;
9
- import jp.classmethod.aws.gradle.lambda.AWSLambdaCreateAliasTask ;
10
- import jp.classmethod.aws.gradle.lambda.AWSLambdaUpdateAliasTask ;
11
-
2
+ import com.amazonaws.services.lambda.model.InvocationType
3
+ import jp.classmethod.aws.gradle.lambda.AWSLambdaDeleteFunctionTask
4
+ import jp.classmethod.aws.gradle.lambda.AWSLambdaInvokeTask
5
+ import jp.classmethod.aws.gradle.lambda.AWSLambdaMigrateFunctionTask
6
+ import jp.classmethod.aws.gradle.lambda.AWSLambdaPublishVersionTask
7
+ import jp.classmethod.aws.gradle.lambda.AWSLambdaCreateAliasTask
8
+ import jp.classmethod.aws.gradle.lambda.AWSLambdaUpdateAliasTask
12
9
import jp.classmethod.aws.gradle.lambda.VpcConfigWrapper
13
10
14
11
buildscript {
15
- repositories {
16
- mavenCentral()
17
- maven { url " https://plugins.gradle.org/m2/" }
18
-
19
- }
20
- dependencies {
21
- classpath " jp.classmethod.aws:gradle-aws-plugin:0.+"
22
- }
12
+ repositories {
13
+ mavenCentral()
14
+ maven { url " https://plugins.gradle.org/m2/" }
15
+
16
+ }
17
+ dependencies {
18
+ classpath " jp.classmethod.aws:gradle-aws-plugin:0.+"
19
+ }
23
20
}
24
21
25
- apply plugin :' base'
22
+ apply plugin : ' base'
26
23
apply plugin : " jp.classmethod.aws.lambda"
27
24
aws {
28
- profileName = " default"
29
- region = " ap-northeast-1"
25
+ profileName = " default"
26
+ region = " ap-northeast-1"
30
27
}
31
28
32
29
lambda {
33
- region = " us-east-1"
30
+ region = " us-east-1"
34
31
}
35
32
36
33
task zip(type : Zip ) {
37
- from " function/"
38
- destinationDir file(" build" )
34
+ from " function/"
35
+ destinationDir file(" build" )
39
36
}
40
37
41
38
task migrateFunction(type : AWSLambdaMigrateFunctionTask , dependsOn : zip) {
42
- functionName = " foobar"
43
- role = " arn:aws:iam::${ aws.accountId} :role/lambda-poweruser"
44
- zipFile = zip. archivePath
45
- handler = " DecodeBase64.handler"
46
- runtime = " Nodejs43"
47
-
48
- environment = [
49
- TARGET : " ascii"
50
- ]
51
-
52
- // optional publish value
53
- publish = true
39
+ functionName = " foobar"
40
+ role = " arn:aws:iam::${ aws.accountId} :role/lambda-poweruser"
41
+ zipFile = zip. archivePath
42
+ handler = " DecodeBase64.handler"
43
+ runtime = " Nodejs43"
44
+
45
+ environment = [
46
+ TARGET : " ascii"
47
+ ]
48
+
49
+ // optional publish value
50
+ publish = true
54
51
}
55
52
56
53
task migrateFunctionWithVpc(type : AWSLambdaMigrateFunctionTask , dependsOn : zip) {
57
- functionName = " foobar"
58
- role = " arn:aws:iam::${ aws.accountId} :role/lambda-poweruser"
59
- zipFile = zip. archivePath
60
- handler = " DecodeBase64.handler"
61
- runtime = " Nodejs43"
54
+ functionName = " foobar"
55
+ role = " arn:aws:iam::${ aws.accountId} :role/lambda-poweruser"
56
+ zipFile = zip. archivePath
57
+ handler = " DecodeBase64.handler"
58
+ runtime = " Nodejs43"
62
59
63
- // optional VPC config
64
- vpc = new VpcConfigWrapper ()
65
- vpc. subnetIds = [" subnet-A" , " subnet-B" ]
66
- vpc. securityGroupIds = [" sg-A" , " sg-B" ]
60
+ // optional VPC config
61
+ vpc = new VpcConfigWrapper ()
62
+ vpc. subnetIds = [" subnet-A" , " subnet-B" ]
63
+ vpc. securityGroupIds = [" sg-A" , " sg-B" ]
67
64
68
65
}
69
66
70
67
task invokeFunction(type : AWSLambdaInvokeTask ) {
71
- functionName = " foobar"
72
- invocationType = InvocationType.RequestResponse
73
- payload = file(" sample-input/input.txt" )
74
- doLast {
75
- println " Lambda function result: " + new String (invokeResult. payload. array(), " UTF-8" )
76
- }
68
+ functionName = " foobar"
69
+ invocationType = InvocationType.RequestResponse
70
+ payload = file(" sample-input/input.txt" )
71
+ doLast {
72
+ println " Lambda function result: " + new String (invokeResult. payload. array(), " UTF-8" )
73
+ }
74
+ }
75
+
76
+ class MyLambdaInvokeTask extends AWSLambdaInvokeTask {
77
+ private static String DEFAULT_DATA = ' SGVsbG8sIHRoaXMgaXMgYW5vdGhlciB0ZXN0IDEyMy4='
78
+ String functionName = " foobar"
79
+ InvocationType invocationType = InvocationType.RequestResponse
80
+
81
+ @Input
82
+ @Option (option = " data" , description = " Data to send" )
83
+ String data = DEFAULT_DATA
84
+
85
+ Object getPayload () {
86
+ return ' {"data": "' + data + ' "}'
87
+ }
88
+ }
89
+
90
+ /*
91
+ * Invoke the function/lambda with a custom (optional) parameter "data".
92
+ * Invoke: gradle invokeFunctionWithCustomDataParameter --data "SGVsbG8gd29ybGQh"
93
+ * Get task description: gradle -q help --task invokeFunctionWithCustomDataParameter
94
+ */
95
+ task invokeFunctionWithCustomDataParameter(type : MyLambdaInvokeTask ) {
96
+ doLast {
97
+ println " Lambda function result: " + new String (invokeResult. payload. array(), " UTF-8" )
98
+ }
77
99
}
78
100
79
101
task deleteFunction(type : AWSLambdaDeleteFunctionTask ) {
80
- functionName = " foobar"
102
+ functionName = " foobar"
81
103
}
82
104
83
105
task publishVersionFunction(type : AWSLambdaPublishVersionTask , dependsOn : migrateFunction) {
84
- functionName = " foobar"
106
+ functionName = " foobar"
85
107
}
86
108
87
109
task createAlias(type : AWSLambdaCreateAliasTask , dependsOn : publishVersionFunction) {
88
- functionName = " foobar"
89
- aliasName = " alias"
90
- functionVersion = " 1"
110
+ functionName = " foobar"
111
+ aliasName = " alias"
112
+ functionVersion = " 1"
91
113
}
92
114
93
115
task updateAlias(type : AWSLambdaUpdateAliasTask , dependsOn : createAlias) {
94
- functionName = " foobar"
116
+ functionName = " foobar"
95
117
aliasName = " alias"
96
- functionVersion = " 1"
118
+ functionVersion = " 1"
97
119
routingConfig {
98
120
additionalVersionWeight = 0.7
99
- useNextVersion = true
121
+ useNextVersion = true
100
122
}
101
- }
123
+ }
0 commit comments