forked from classmethod/gradle-aws-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancements to cloudformation and AWSLambdaInvokeTask
- Loading branch information
1 parent
2aa9332
commit 02743db
Showing
13 changed files
with
371 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
apply plugin: 'groovy' | ||
apply plugin: 'jp.classmethod.aws.cloudformation' | ||
|
||
apply from: 'deploy-dev.groovy' | ||
|
||
import jp.classmethod.aws.gradle.s3.SyncTask | ||
import jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationPluginExtension | ||
|
||
group 'example' | ||
version = "SNAPSHOT-${project.rootProject.startTime.format('yyMMddHHmm')}" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile 'org.codehaus.groovy:groovy-all:2.4.4' | ||
compile 'com.amazonaws:aws-lambda-java-core:1.0.0' | ||
} | ||
|
||
task buildZip(type: Zip) { | ||
from compileGroovy | ||
from processResources | ||
into('lib') { | ||
from configurations.runtime | ||
} | ||
} | ||
|
||
build.dependsOn buildZip | ||
|
||
task uploadLamdbdaToS3(type: SyncTask) { | ||
dependsOn build | ||
|
||
delete true | ||
bucketName "${cloudFormation.stackParams['pArtifactBucket']}" | ||
prefix "${cloudFormation.stackParams['pArtifactPrefix']}/" | ||
source file("$buildDir/distributions") | ||
} | ||
|
||
task updateStack (dependsOn: [uploadLamdbdaToS3, awsCfnMigrateStackAndWaitCompleted]) { | ||
group 'CNN' | ||
description "Creates/Updates $cloudFormation.stackName stack" | ||
} | ||
|
||
task deleteStack (dependsOn: awsCfnDeleteStackAndWaitCompleted) { | ||
group 'CNN' | ||
description "Deletes $cloudFormation.stackName stack" | ||
} | ||
|
||
awsCfnMigrateStack.mustRunAfter uploadLamdbdaToS3 | ||
awsCfnWaitStackComplete.loopTimeout = 10800 // = 3hr | ||
awsCfnWaitStackDeleted.loopTimeout = 10800 // = 3hr | ||
|
||
task getStackInfo { | ||
doLast { | ||
def stackName = cloudFormation.getStackOutputValue('StackName') | ||
def lambdaArn = cloudFormation.getStackOutputValue('LambdaArn') | ||
|
||
println """ | ||
$stackName | ||
$lambdaArn""" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Description: A groovy lambda | ||
Parameters: | ||
pArtifactBucket: | ||
Description: The name of the S3 bucket that contains the source code of your Lambda | ||
function. | ||
Type: String | ||
pArtifactPrefix: | ||
Description: Prefix of the objects for the Lambdas | ||
Type: String | ||
pHelloWorldZipFile: | ||
Description: The location and name of your source code .zip file. | ||
Type: String | ||
Resources: | ||
HelloWorld: | ||
Type: AWS::Lambda::Function | ||
Properties: | ||
Code: | ||
S3Bucket: | ||
Ref: pArtifactBucket | ||
S3Key: | ||
Fn::Join: | ||
- "/" | ||
- - Ref: pArtifactPrefix | ||
- Ref: pHelloWorldZipFile | ||
Handler: example.Hello::myHandler | ||
Runtime: java8 | ||
Description: A groovy lambda | ||
MemorySize: 512 | ||
Timeout: 15 | ||
Role: arn:aws:iam::123456789012:role/lambda_basic_execution | ||
Outputs: | ||
StackName: | ||
Description: StackName | ||
Value: | ||
Ref: AWS::StackName | ||
LambdaArn: | ||
Description: Lambda ARN | ||
Value: | ||
Fn::GetAtt: | ||
- HelloWorld | ||
- Arn |
14 changes: 14 additions & 0 deletions
14
samples/06A-cloudformation/cloudformation/stackpolicy.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"Statement" : [ | ||
{ | ||
"Resource": "*", | ||
"Effect": "Allow", | ||
"Principal": "*", | ||
"Action": [ | ||
"Update:Modify", | ||
"Update:Delete", | ||
"Update:Replace" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
aws { | ||
profileName = "default" | ||
region = "ap-northeast-1" | ||
} | ||
|
||
cloudFormation { | ||
stackName "HelloWorld-stack" | ||
capabilityIam true | ||
templateFile project.file('cloudformation/HelloWorld.yml') | ||
stackPolicyFile project.file('cloudformation/stackpolicy.json') | ||
onFailure 'DO_NOTHING' | ||
|
||
stackParams ([ | ||
'pArtifactBucket': 'my-deploy-dev', | ||
'pArtifactPrefix': 'helloworld-example', | ||
|
||
'pHelloWorldZipFile' : "06A-cloudformation-${-> version}.zip" | ||
]) | ||
} |
15 changes: 15 additions & 0 deletions
15
samples/06A-cloudformation/src/main/groovy/example/Hello.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Borrowed from https://medium.com/@benorama/how-to-build-a-microservice-with-aws-lambda-in-groovy-4f7384c3b804#.9z2rs5hud | ||
// | ||
|
||
package example | ||
|
||
import com.amazonaws.services.lambda.runtime.Context | ||
|
||
class Hello { | ||
Map myHandler(data, Context context) { | ||
context.logger.log "received in groovy: $data" | ||
[greeting: "Hello, ${data?.firstName} ${data?.lastName}".toString()] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.