Giter Club home page Giter Club logo

aws-ant-task's Introduction

#Simple AWS ANT Task

Features:

  • CloudFront invalidation requests
  • S3 File upload using fileset strategy
  • SimpleDB insert rows [dynamic attributes]
<?xml version="1.0" encoding="utf-8"?>
<project name="MyProjectName" basedir="." default="cdn-invalidation">

    <!-- Other ant tasks -->

    <target name="cdn-invalidation" description="Invalidation of static files">
        <taskdef name="cloudfront" classpath="aws-ant-task.jar" classname="it.corley.ant.CloudFront" />
        <cloudfront key="your-key" secret="your-secret-key" distributionId="your-distribution-id">
            <delete path="/js/folder/my-path.js"/>
            <delete path="/css/folder/my-path.css"/>
            <delete path="/direct-gen.txt"/>
        </cloudfront>
    </target>

    <!-- Or you can also use one string -->

    <target name="cdn-invalidation-through-list" description="Invalidation of static files">
        <taskdef name="cloudfront" classpath="aws-ant-task.jar" classname="it.corley.ant.CloudFront" />
        <cloudfront key="your-key" secret="your-secret-key" distributionId="your-distribution-id"
                    pathsString="/js/folder/my-path.js,/css/folder/my-path.css,/direct-gen.txt" />
    </target>

</project>

Simple S3 Task

Added a very simple S3 task that enable files upload

<taskdef name="s3" classpath="aws-ant-task.jar" classname="it.corley.ant.S3PutTask" />
<s3 endpoint="s3-eu-west-1.amazonaws.com" key="your-key" secret="your-secret" bucket="your-bucket-name" dest="path/to/file">
    <fileset dir="my/dir" includes="**/*.html" />
</s3>

File upload using default Ant fileset strategy.

<taskdef name="s3put" classpath="aws-ant-task.jar" classname="it.corley.ant.S3PutTask" />
<s3put endpoint="s3-eu-west-1.amazonaws.com" key="your-key" secret="your-secret" bucket="your-bucket-name" dest="path/to/file">
  <fileset dir="${public.src}" casesensitive="yes">
    <patternset id="non.test.sources">
      <include name="**/*.js"/>
      <exclude name="**/*Test*"/>
    </patternset>
  </fileset>
</s3put>

Mark public files using publicRead

Consider that public property (Grant Everyone open/doownload) is marked on each file scanned by fileset directive. Your bucket rule is never touched.

<s3put
    endpoint="s3-eu-west-1.amazonaws.com"
    key="your-key"
    secret="your-secret"
    bucket="your-bucket-name"
    dest="path/to/file"
    publicRead="true">
    <!-- fileset structure -->
</s3put>

Easily configure content types using contentType property or ContentTypeMapping type

Global Content-Type configuration:

<s3put
    endpoint="s3-eu-west-1.amazonaws.com"
    key="your-key"
    secret="your-secret"
    bucket="your-bucket-name"
    dest="path/to/file"
    contentType="application/x-whatever">
    <!-- fileset structure -->
</s3put>

Content-Type mappers:

<typedef name="contenttypemapping" classname="it.corley.ant.ContentTypeMapping" classpathref="tasks.path"/>
<s3put
    endpoint="s3-eu-west-1.amazonaws.com"
    key="your-key"
    secret="your-secret"
    bucket="your-bucket-name"
    dest="path/to/file"
    contentType="application/x-whatever">
    <fileset dir="dist" include="**/*"/>
    <contenttypemapping extension=".crx" contenttype="application/x-chrome-extension"/>
    <contenttypemapping extension=".xpi" contenttype="application/x-xpinstall"/>
</s3put>

Note then when setting global content-type using contentType property of the s3put task and setting mapping using contenttype.mapping, the mapping takes precedence if given.

Easily configure cache control using cacheControl property

Global Cache-Control configuration:

<s3put
    endpoint="s3-eu-west-1.amazonaws.com"
    key="your-key"
    secret="your-secret"
    bucket="your-bucket-name"
    dest="path/to/file"
    contentType="application/x-whatever"
    cacheControl="max-age=3600">
    <!-- fileset structure -->
</s3put>

Cache-Control mappers:

<typedef name="cachecontrol.mapping" classname="it.corley.ant.CacheControlMapping" classpathref="tasks.path"/>
<s3put
    endpoint="s3-eu-west-1.amazonaws.com"
    key="your-key"
    secret="your-secret"
    bucket="your-bucket-name"
    dest="path/to/file"
    contentType="application/x-whatever">
    <fileset dir="dist" include="**/*"/>
    <contenttypemapping extension=".crx" contenttype="application/x-chrome-extension"/>
    <contenttypemapping extension=".xpi" contenttype="application/x-xpinstall"/>
    <cachecontrolmapping extension=".js" maxage="14400"/>
    <cachecontrolmapping extension=".css" maxage="86400"/>
</s3put>

Easily configure content encoding using contentEncoding property

Global Content-Encoding configuration:

<s3put
    endpoint="s3-eu-west-1.amazonaws.com"
    key="your-key"
    secret="your-secret"
    bucket="your-bucket-name"
    dest="path/to/file"
    contentType="application/x-whatever"
    contentEncoding="UTF-8">
    <!-- fileset structure -->
</s3put>

Content-Encoding mappers:

<typedef name="contentencoding.mapping" classname="it.corley.ant.ContentEncodingMapping" classpathref="tasks.path"/>
<s3put
    endpoint="s3-eu-west-1.amazonaws.com"
    key="your-key"
    secret="your-secret"
    bucket="your-bucket-name"
    dest="path/to/file"
    contentType="application/x-whatever">
    <fileset dir="dist" include="**/*"/>
    <contenttypemapping extension=".crx" contenttype="application/x-chrome-extension"/>
    <contenttypemapping extension=".xpi" contenttype="application/x-xpinstall"/>
    <cachecontrolmapping extension=".js" maxage="14400"/>
    <cachecontrolmapping extension=".css" maxage="86400"/>
    <contentencoding extension=".js" encoding="gzip"/>
    <contentencoding extension=".css" encoding="gzip"/>
</s3put>

Easily download a file from S3

<taskdef name="s3get" classpath="aws-ant-task.jar" classname="it.corley.ant.S3GetTask" />
<s3get endpoint="s3-eu-west-1.amazonaws.com"
       key="your-key" secret="your-secret"
       bucket="your-bucket-name" src="path/to/file"
       dest="path/to/file" />

SimpleDB Task

Read attributes from a row in your SimpleDB domain using

<taskdef name="simpledbget" classpath="aws-ant-task-${version}.jar" classname="it.corley.ant.SimpleDBGetTask" />
<simpledbget key="your-key" secret="your-secret"
             domain="your-domain" region="your-sdb-region"
             itemName="1234" attributes="my_property,another_property"
             propertyprefix="row" />

<echo message="my_property=${row.my_property}" />
<echo message="another_property=${row.another_property}." />

This task will fail if an unknown item name or attribute is used.

Insert new rows into your SimpleDB domain using

<taskdef name="simpledb" classpath="aws-ant-task-${version}.jar" classname="it.corley.ant.SimpleDB" />
<simpledb key="your-key" secret="your-secret" domain="your-domain" region="your-sdb-region">
    <attribute name="my_property" value="my first value" />
    <attribute name="another_property" value="value for this property" />
</simpledb>

You can replace existing rows into your SimpleDB domain using

<taskdef name="simpledb" classpath="aws-ant-task-${version}.jar" classname="it.corley.ant.SimpleDB" />
<simpledb key="your-key" secret="your-secret" domain="your-domain" region="your-sdb-region">
    <attribute name="itemName()" value="my first value" />
    <attribute name="another_property" value="new value for this property" />
    <attribute name="yet_another_property" value="new value for this property" append="true" />
</simpledb>

By default the attribute values for the row will be replaced. Add append="true" to your attribute to append the value, instead of overwriting it.

You have to download the latest aws-ant-task.jar binary file and add it into your project. Configure a new task as previous example.

Building and installing

With tests:

cp test.properties.dist test.properties
# Fill the test.properties accordingly
mvn package

or without them:

mvn package -Dmaven.test.skip=true

After properly building the tasks, all the jars needed to use them can be found in target/aws-ant-tasks-0.1-SNAPSHOT-bin directory. Just copy it whenever you like and use external classpath when defining the tasks:

<!-- Task for setting up the aws-ant-tasks -->
<target name="awstasks.setup">
    <path id="tasks.path">
        <fileset dir="target/aws-ant-tasks-0.1-SNAPSHOT-bin" includes="*.jar"/>
    </path>

    <taskdef name="s3put" classpath="aws-ant-task-${version}.jar" classname="it.corley.ant.S3PutTask"
             classpathref="tasks.path"/>
    <typedef name="contenttype.mapping" classname="it.corley.ant.ContentTypeMapping" classpathref="tasks.path"/>
</target>


<!--Actual use -->
<target name="use" description="Use the Task" depends="awstasks.setup">

</target>

Or copy them to the $ANT_HOME/libs directory and use directly, without specifying the classpath.

Contributors

This project is maintained by Corley S.r.l. and released under MIT license. A special thanks goes to our contributors! Thanks guys!

https://github.com/corley/aws-ant-task/graphs/contributors

Feel free to contribute to this project with your requests and pull requests!

aws-ant-task's People

Contributors

arjenvanderende avatar elieladelrom avatar jalkjaer avatar q42jaap avatar shalupov avatar stoiczek avatar wdalmut avatar webrat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

aws-ant-task's Issues

Pepijn Schmitz proposal

Just applied a patch proposed by Pepijn Schmitz.

Pepijn Schmitz:

I made some changes to the S3PutTask class so that it supports putting
objects in the root (as well as making the destination handling slightly
more intuitive). I also added support for storing objects with reduced
redundancy.

Cachecontrol headers issue: s3put doesn't support the nested "cachecontrol" element.

Hi, great task...

Following docs in README, woudl expect the following config to work:

<s3put endpoint="s3-eu-west-1.amazonaws.com" 
        key="${s3.access.key}" 
        secret="${s3.secret.key}" 
        bucket="${AWS_BUCKET}" 
        dest=""
        cachecontrol="max-age=60">
                        <cachecontrol extension=".js" maxage="86400"/>
                        <fileset dir="${dir.deploy}" includes="**/*" />
</s3put>

but getting...
s3put doesn't support the nested "cachecontrol" element.

Am I misusing?

Thanks

contentEncoding attribute?

Would be helpful to add a contentEncoding attribute for uploading to s3.

This would make it easy to upload gzipped javascript [ see http://stackoverflow.com/a/5447158/62255 ]

S3GetTask 404 Errors

I am struggling with trying to get S3Get to work. I get as far as this process:

dist:
[s3get] Downloading 'build-cssdk/win-pthreads.zip' to 'dist'
[s3get] Using credentials from ant build file
[s3get] Region s3.amazonaws.com provided

So far I've compiled the latest aws-ant-tasks-0.5-SNAPSHOT.jar and tried using it. Cannot download from my bucket.

Made one change to try to troubleshoot.

 <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.8.4</version>

Not a Maven/Java coder, so fumbling through.

AmazonS3Exception: Status Code: 404, AWS Service: Amazon S3, AWS Request ID: HIDDEN_FROM_THIS_POST, AWS Error Code: null, AWS Error Message: Not Found, S3 Extended Request ID: HIDDEN_FROM_THIS_POST
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:679)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:350)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:202)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3001)
at com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(AmazonS3Client.java:801)
at com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(AmazonS3Client.java:781)
at com.amazonaws.services.s3.transfer.TransferManager.download(TransferManager.java:478)
at com.amazonaws.services.s3.transfer.TransferManager.download(TransferManager.java:456)
at it.corley.ant.S3GetTask.downloadFile(S3GetTask.java:65)
at it.corley.ant.S3GetTask.execute(S3GetTask.java:39)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

wrong endpoint?

I am unable to use s3put to upload files to my bucket.

com.amazonaws.AmazonClientException: Unable to execute HTTP request: bucket-name.s3-us-east-1.amazonaws.com
...
Caused by: java.net.UnknownHostException: bucket-name.s3-us-east-1.amazonaws.com

Do I need to enable Static Website Hosting? Maybe I have used the wrong endpoint address?
bucket-name.s3-website-us-east-1.amazonaws.com

( I used my static website hosting endpoint as a starting point for determining what my endpoint is.)

Allow cache control to be string

Currently cache control is accepting only integer values used for max-age:
https://github.com/corley/aws-ant-task/blob/master/src/main/it/corley/ant/S3PutTask.java#L216

Cache control header could be more than just max-age in general case, you currently cannot set something like:
Cache-Control: max-age=3600, must-revalidate

List of possible values (scroll to 14.9):
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

Possible solution could be checking if passed value is integer then using it as max-age value (to not break old codebase), otherwise just pass the value as is without prepending max-age for full flexibility.

Binary 1.3 JAR is not downloadable

Hi,
could someone please reup the 1.3 jar file...
I got the 1.2 file running, but it seems to miss a few functions.
i´m a total noob an can´t get the 1.3 compiled :(

secret security?

Maybe this is not the right place for this question, and if so, please close this ticket.

I am wondering if there is a protocol for keeping AWS secret, well, secret from other people when using this ANT task? Imagine: we have a team of people making uploads, but do not want to give everyone a copy of the secret. What would you suggest? Thanks!

WARNING: Unable to execute HTTP request: my-bucket.US

Trying to use s3put to upload some files, but hitting a wall. Suggestions? Here is what ANT says:

s3put
Region US given but not found in the region to endpoint map. Will use it as an endpoint
Uploading 1 file(s) from C:\dev\my_js\build
Oct 30, 2012 5:51:43 PM com.amazonaws.http.AmazonHttpClient executeHelper
WARNING: Unable to execute HTTP request: my-bucket.US
C:\dev\my_js\ant\build.xml:49: com.amazonaws.AmazonClientException: Unable to execute HTTP request: my-bucket.US

Windows 7, JRE1.6.0_27

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.