Giter Site home page Giter Site logo

gradle-aws-plugin's Introduction

Gradle AWS Plugin

Join the chat at https://gitter.im/gradle-aws-plugin/Lobby

Gradle plugin to manage AWS resouces.

Current Features / Supported AWS Products

  • S3
    • Create bucket
    • Delete bucket
    • Upload object(s)
    • Delete object(s)
    • File sync
    • Set bucket policy
  • EC2
    • Run instance
    • Start instance
    • Stop instance
    • Terminate instance
    • Import key
    • Authorize security group ingress permissions
    • Authorize security group egress permissions
    • Revoke security group ingress permissions
    • Revoke security group egress permissions
    • Wait instance for specific status
  • RDS
    • Create DB instance
    • Delete DB instance
    • Modify DB instance
    • Migrate (create or modify) DB instance
    • Reboot DB instance
    • Wait DB instance for specific status
  • Route53
    • Create hosted zone
    • Delete hosted zone
    • Change record set
  • Elastic Beanstalk
    • Create or delete applications
    • Create or terminate environments
    • Create or delete configuration templates
    • Create or delete application versions
    • Wait environment for specific status
  • CloudFormation
    • Migrate (create or update) stack
    • Delete stack
    • Wait stack for specific status
  • Lambda
    • Create function
    • Update function code
    • Update function configuration
    • Migrate (create or update) function
    • Invoke function
    • Delete function
  • IAM
    • Create role
    • Attach role policy
  • ELB
    • (TBD)
  • SQS
    • Send messages
    • Delete messages
    • Read messages
  • SNS
    • Publish message
  • SSM
    • Put parameters

Requirements

  • Java 8+
  • Gradle 2.4+

How to use?

Add like this to your build.gradle :

buildscript {
  repositories {
    mavenCentral()
    maven { url "https://plugins.gradle.org/m2/" }
  }
  dependencies {
    classpath "jp.classmethod.aws:gradle-aws-plugin:0.30"
  }
}

apply plugin: 'jp.classmethod.aws'

aws {
  profileName = 'credentials-profile-name-in-your-profile-configuration-file (~/.aws/credentials)'
  region = 'ap-northeast-1'
}

These credentials are used to make API accesses by default. The format of the credentials file is described in the Amazon AWS Docs.

S3 Create bucket

apply plugin: 'jp.classmethod.aws.s3'

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
}

Look S3 example 1

S3 files tasks

apply plugin: 'jp.classmethod.aws.s3'

task syncObjects(type: jp.classmethod.aws.gradle.s3.SyncTask) {
  bucketName 'foobar.example.com'
  source file('path/to/objects')
}

Look S3 example 1 and S3 example 2 for more information.

EC2 instance tasks

apply plugin: 'jp.classmethod.aws.ec2'

// You can overwrite default credentials and region settings like this:
// ec2 {
//   profileName 'another-credentials-profile-name' // optional
//   region = 'us-east-1'
// }

task stopBastion(type: jp.classmethod.aws.gradle.ec2.AmazonEC2StopInstanceTask) {
  instanceIds += 'i-12345678'
}

task startBastion(type: jp.classmethod.aws.gradle.ec2.AmazonEC2StartInstanceTask) {
  instanceIds += 'i-12345678'
}

Look EC2 example for more information.

RDS DB instance tasks

apply plugin: "jp.classmethod.aws.rds"

// You can overwrite default credentials and region settings like this:
// rds {
//   profileName 'another-credentials-profile-name' // optional
//   region = 'us-east-1'
// }

task migrateDBInstance(type: AmazonRDSMigrateDBInstanceTask) {
	dbInstanceIdentifier = "foobar"
	allocatedStorage = 5
	dbInstanceClass = "db.t2.micro"
	engine = "MySQL"
	masterUsername = "root"
	masterUserPassword = "passW0rd"
	vpcSecurityGroupIds = [ "sg-d3958fbf" ]
	dbSubnetGroupName = "default"
	multiAZ = false
	publiclyAccessible = true
}

task rebootDBInstance(type: AmazonRDSRebootDBInstanceTask) {
	dbInstanceIdentifier = "foobar"
}

task deleteDBInstance(type: AmazonRDSDeleteDBInstanceTask) {
	dbInstanceIdentifier = "foobar"
	skipFinalSnapshot = true
}

Look RDS example for more information.

Route 53 hosted zone tasks

apply plugin: 'jp.classmethod.aws.route53'

ask createHostedZone(type: jp.classmethod.aws.gradle.route53.CreateHostedZoneTask) {
	hostedZoneName "foobar.example.com"
	callerReference '0BF44985-9D79-BF3B-A9B0-5AE24D6E86E1'
}

task deleteHostedZone(type: jp.classmethod.aws.gradle.route53.DeleteHostedZoneTask) {
	hostedZoneId "XXXX"
}

Look Route 53 example for more information.

Elastic Beanstalk environemnt tasks

apply plugin: 'jp.classmethod.aws.beanstalk'
beanstalk {
  String extension = project.war.archiveName.tokenize('.').last()
  String timestamp = new Date().format("yyyyMMdd'_'HHmmss", TimeZone.default)

  appName 'foobar'
  appDesc 'foobar demo application'
  
  version {
    label = "foobar-${project.war.version}-${timestamp}"
    description = "${artifactId} v${version}"
    bucket = 'sample-bucket'
    key = "eb-apps/foobar-${project.war.version}-${timestamp}.${extension}"
  }
  
  configurationTemplates {
    production {
      optionSettings = file('src/main/config/production.json')
      solutionStackName = '64bit Amazon Linux 2013.09 running Tomcat 7 Java 7'
    }
    development {
      optionSettings = file('src/main/config/development.json')
      solutionStackName = '64bit Amazon Linux 2013.09 running Tomcat 7 Java 7'
    }
  }
  
  environment {
    envName = 'foobar'
    envDesc = 'foobar demo application development environemnt'
    templateName = 'development'
    versionLabel = "foobar-${project.war.version}-${timestamp}"
  }
}

// task awsEbMigrateEnvironment, awsEbDeleteApplication and so on are declared

Look Elastic Beanstalk example for more information.

CloudFormation stack tasks

apply plugin: 'jp.classmethod.aws.cloudformation'

cloudFormation {
  stackName 'foobar-stack'
  stackParams([
    Foo: 'bar',
    Baz: 'qux'
  ])
  stackTags([
    Bar: 'foo',
    Baz: 'fox'
  })
  capabilityIam true
  templateFile project.file("foobar.template")
  templateBucket 'example-bucket'
  templateKeyPrefix 'foobar/'
}

// awsCfnMigrateStack and awsCfnDeleteStack task (and so on) is declared.

Look CloudFormation example for more information.

Lambda function tasks

apply plugin: "base"
apply plugin: "jp.classmethod.aws.lambda"
aws {
	profileName = "default"
	region = "ap-northeast-1"
}

lambda {
	region = "us-east-1"
}

task zip(type: Zip) {
	from "function/"
	destinationDir file("build")
}

task migrateFunction(type: AWSLambdaMigrateFunctionTask, dependsOn: zip) {
	functionName = "foobar"
	role = "arn:aws:iam::${aws.accountId}:role/lambda-poweruser"
	zipFile = zip.archivePath
	handler = "DecodeBase64.handler"
	environment = [
	    p1: "Value",
	    p2: "Value2"
	]
}

task invokeFunction(type: AWSLambdaInvokeTask) {
	functionName = "foobar"
	invocationType = InvocationType.RequestResponse
	payload = file("sample-input/input.txt")
	doLast {
		println "Lambda function result: " + new String(invokeResult.payload.array(), "UTF-8")
	}
}

task deleteFunction(type: AWSLambdaDeleteFunctionTask) {
	functionName = "foobar"
}

Look Lambda example for more information.

SQS tasks

apply plugin: "jp.classmethod.aws.sqs"

task sendMessages(type: AmazonSQSSendMessagesTask) {
	queueName 'gradle-aws-plugin-sample'
	messages Stream.of("Test 1", "Test 2")
}

task deleteMessages(type: AmazonSQSMessageConsumerTask) {
	queueName 'gradle-aws-plugin-sample'
	showMessages false
}

task viewMessages(type: AmazonSQSMessageConsumerTask) {
	queueName 'gradle-aws-plugin-sample'
	deleteMessages false
	maxNumberOfMessages 50
}

Look SQS example for more information.

SNS tasks

apply plugin: "jp.classmethod.aws.sns"

task publishMessage(type: AmazonSNSPublishMessageTask) {
	topicArn 'arn:aws:sns:us-east-1:000000000000:gradle-aws-plugin-sns-topic'
	message 'Test body'
	subject 'Optional test subject'
}

task publishJsonMessage(type: AmazonSNSPublishMessageTask) {
	topicArn 'arn:aws:sns:us-east-1:000000000000:gradle-aws-plugin-sns-topic'
	message JsonOutput.toJson(['default': 'Default message body.',
							   'email'  : 'Email message body.',
							   'sms': 'SMS message body.'])
	messageStructure 'json'
}

Look SNS example for more information.

License

Copyright (C) 2013-2015 Classmethod, Inc.

Distributed under the Apache License v2.0. See the file copyright/LICENSE.txt.

Development and Contribution

We will open for contributions.

To contribute to the plugin or make your own modifications, including the ability to publish your build artifacts to your own maven repository see: development.

gradle-aws-plugin's People

Contributors

adamantyr avatar atschabu avatar centic9 avatar dai0304 avatar donalhenry avatar gitter-badger avatar glebsts avatar isaacaggrey avatar lnr0626 avatar lugoues avatar mochizuki-masao avatar mrburrito avatar rafe-delphix avatar robbypond avatar sdavids13 avatar tellary avatar tsuyoyo avatar wgorski-antrego avatar yissachar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.