This shows you the differences between two versions of the page.
aws_gradle [2017/10/06 07:46] root created |
aws_gradle [2018/07/16 07:29] (current) root [API Plugin] |
||
---|---|---|---|
Line 5: | Line 5: | ||
+ | == gradle-aws-plugin:0.+ == | ||
+ | |||
+ | <code groovy> | ||
+ | import com.amazonaws.services.lambda.model.InvocationType | ||
+ | import jp.classmethod.aws.gradle.lambda.AWSLambdaInvokeTask | ||
+ | import jp.classmethod.aws.gradle.lambda.AWSLambdaMigrateFunctionTask | ||
+ | import com.amazonaws.services.lambda.model.Runtime | ||
+ | import jp.classmethod.aws.gradle.s3.CreateBucketTask | ||
+ | import jp.classmethod.aws.gradle.s3.DeleteBucketTask | ||
+ | import com.amazonaws.services.s3.model.ObjectMetadata | ||
+ | import jp.classmethod.aws.gradle.s3.AmazonS3FileUploadTask | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | buildscript { | ||
+ | repositories { | ||
+ | mavenCentral() | ||
+ | maven { url "https://plugins.gradle.org/m2/" } | ||
+ | } | ||
+ | dependencies { | ||
+ | classpath "com.github.jengelman.gradle.plugins:shadow:2.0.4" | ||
+ | classpath "io.spring.gradle:dependency-management-plugin:1.0.5.RELEASE" | ||
+ | classpath "net.ltgt.gradle:gradle-apt-plugin:0.15" | ||
+ | classpath "jp.classmethod.aws:gradle-aws-plugin:0.+" | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | apply plugin:"io.spring.dependency-management" | ||
+ | apply plugin:"com.github.johnrengelman.shadow" | ||
+ | apply plugin:"application" | ||
+ | apply plugin:"java" | ||
+ | apply plugin: 'jp.classmethod.aws.lambda' | ||
+ | apply plugin: 'jp.classmethod.aws.s3' | ||
+ | |||
+ | sourceCompatibility = 1.8 | ||
+ | targetCompatibility = 1.8 | ||
+ | |||
+ | |||
+ | group 'wtr' | ||
+ | version '1.0-SNAPSHOT' | ||
+ | |||
+ | |||
+ | ext { | ||
+ | springboot = '2.0.3.RELEASE' | ||
+ | |||
+ | } | ||
+ | |||
+ | repositories { | ||
+ | mavenCentral() | ||
+ | maven { | ||
+ | url 'https://repo.spring.io/plugins-release' | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | dependencies { | ||
+ | compile "org.springframework.boot:spring-boot-starter-web:${springboot}" | ||
+ | compile "org.springframework.boot:spring-boot-dependencies:${springboot}" | ||
+ | |||
+ | |||
+ | compile 'com.amazonaws.serverless:aws-serverless-java-container-spring:1.1' | ||
+ | testCompile group: 'junit', name: 'junit', version: '4.12' | ||
+ | runtime "com.amazonaws:aws-lambda-java-log4j2:1.0.0" | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | mainClassName = "salesforce.Application" | ||
+ | |||
+ | |||
+ | shadowJar { | ||
+ | mergeServiceFiles() | ||
+ | } | ||
+ | |||
+ | task deploy(type: AWSLambdaMigrateFunctionTask, dependsOn: shadowJar) { | ||
+ | functionName = "salesforce" | ||
+ | handler = "wtr.salesforce.StreamLambdaHandler::handleRequest" | ||
+ | role = "arn:aws:iam::162428642958:role/aws-java-simple-http-endpoint-dev-us-east-1-lambdaRole" | ||
+ | runtime = Runtime.Java8 | ||
+ | zipFile = shadowJar.archivePath | ||
+ | memorySize = 256 | ||
+ | timeout = 60 | ||
+ | } | ||
+ | |||
+ | task invoke(type: AWSLambdaInvokeTask) { | ||
+ | functionName = "salesforce" | ||
+ | invocationType = InvocationType.RequestResponse | ||
+ | payload = '{"hello" :"world"}' | ||
+ | doLast { | ||
+ | println "Lambda function result: " + new String(invokeResult.payload.array(), "UTF-8") | ||
+ | } | ||
+ | } | ||
+ | |||
+ | aws { | ||
+ | profileName = 'personal' | ||
+ | region = 'eu-west-1' | ||
+ | } | ||
+ | |||
+ | def myBucketName = 'product-data-sample' | ||
+ | def regionName = 'eu-west-1' | ||
+ | |||
+ | |||
+ | task createBucket(type: CreateBucketTask) { | ||
+ | bucketName myBucketName | ||
+ | |||
+ | // one of http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region values, us-east-1 by default | ||
+ | region regionName | ||
+ | // // create bucket only if it does not exist, otherwise skip | ||
+ | ifNotExists true | ||
+ | } | ||
+ | |||
+ | task uploadContent(type: AmazonS3FileUploadTask, dependsOn: createBucket) { | ||
+ | file file("sample-product.json") // must be a file | ||
+ | bucketName myBucketName | ||
+ | key "01-s3-sample-product" | ||
+ | |||
+ | def m = new ObjectMetadata() | ||
+ | m.setCacheControl("no-cache, no-store") | ||
+ | objectMetadata = m | ||
+ | } | ||
+ | </code> |