Showing posts with label operations. Show all posts
Showing posts with label operations. Show all posts

Thursday, July 23, 2015

How to add configuration parameters to AWS lambda with API gateway

Unfortunately, there is no easy way to add configuration parameters to AWS lambdas, there is almost nothing in context that you can configure; there is description, but besides being ambiguous, it is not accessible from function itself. Fortunately, it is possible to set additional values from API gateway, even it is not straightforward.

When you have created API gateway mapping, go to the method screen in gateway console, there is screen with multiple boxes, one of which is called Integration Request, click it and there will be section called Mapping Templates. Add new mapping template for type application/x-www-form-urlencoded, save it, edit value and change from default Input passthrough to Mapping template, then you can transform your original request, by adding additional parameters, it uses velocity for transformation, but there is basic example:


{
  "my-new-configuration" : "my value",
  "body" : "$input.path('$')",
  "params" : "$input.params()",
  "ip" : "$context.identity.sourceIp",
  "user-agent" : "$context.identity.userAgent"
}

Besides possibility to add anything to lambda function it also has access to interesting request data like headers, ip, client type, user agent, country, etc. - all will be available in your map or pojo as parameter for lambda function. And do not forget to click Deploy API after making changes to make them live.

Thursday, June 25, 2015

How to create executable JAR from single Groovy script

Groovy scripts are nice - they allow to use dependencies and write logic in small single file, but Groovy is mostly available on developers machine, but not on servers, so deploying them is a little more tricky. You can package them in uberjar with Gradle, but it requires additional build file and compatible structure, so it is more like project than script already.

To keep things simple, I have created Groovy script that converts other Groovy scripts into executable JARs. It packages all dependencies from Grab and compiles original script into Java main class with same name as script and sets it in manifest. So it is perfectly usable from empty JVM. JAR structure is also compatible with AWS lambda, so it can be launched from there too, just put logic in specific method. To convert your script, just download it from here and run like:

./scriptjar.groovy input.groovy output.jar

Script tries to find groovy libs via GROOVY_HOME, so set it or just hack it for your location, it is just one small Groovy script.

Wednesday, March 4, 2015

Changing SSH port for dynamic inventory script in Ansible

If you have to write dynamic inventory script in Ansible, but need to use SSH port which is not 22, there is example output of the script output:


{"databases":{
    "hosts":["127.0.0.1"],
    "vars":{
        "ansible_ssh_port":2222
        }
    }
}



Saturday, February 21, 2015

Ansible freezes during start

If Ansible stops for several minutes or so during start without any messages, check if it calls your inventory script, because it might query for additional options using --host parameter and if there are a lot of hosts, it may take some time.

It can be easily fixed by adding this to JSON root:

    "_meta" : {
       "hostvars" : {
       }
    }


More about it here.

Friday, January 23, 2015

VirtualBox DHCP gives same IP address to different machines

Usually happens after cloning VMs and problem is because there is the same MAC address. Check virtual machine network settings and change as needed.