Skip to content

Instantly share code, notes, and snippets.

@zwily
Last active December 14, 2015 12:39
Show Gist options
  • Save zwily/5088029 to your computer and use it in GitHub Desktop.
Save zwily/5088029 to your computer and use it in GitHub Desktop.
Straitjacket quickstart.

Getting Started with the StraitJacket AMI

Create a security group:

ec2-create-group straitjacket -d "straitjacket testing"
GROUP	sg-dc1cf8b7	straitjacket	straitjacket testing

Allow port 80 to your new sec group:

ec2-authorize straitjacket -P tcp -p 80
GROUP			straitjacket
PERMISSION		straitjacket	ALLOWS	tcp	80	80	FROM	CIDR	0.0.0.0/0	ingress

Fire up an instance:

ec2-run-instances ami-8de553e4 -g straitjacket
RESERVATION	r-850d4bff	747283455610	straitjacket
INSTANCE	i-2c04015f	ami-8de553e4			pending		0		m1.small	2013-03-07T23:35:30+0000	us-east-1a	aki-825ea7eb			monitoring-disabled					ebs					paravirtual	xen		sg-dc1cf8b7	default

See domain name, see if it's running yet:

ec2-describe-instances i-2c04015f
RESERVATION	r-850d4bff	747283455610	straitjacket
INSTANCE	i-2c04015f	ami-8de553e4	ec2-23-23-52-189.compute-1.amazonaws.com	ip-10-64-39-91.ec2.internal	pending		0		m1.small	2013-03-07T23:35:30+0000	us-east-1a	aki-825ea7eb			monitoring-disabled	23.23.52.189	10.64.39.91			ebs					paravirtual	xen		sg-dc1cf8b7	default
BLOCKDEVICE	/dev/sda1	vol-acf769dc	2013-03-07T23:35:33.000Z	true

(Now wait until your instance is launched.)

Get the list of languages supported

$ curl http://ec2-23-22-253-4.compute-1.amazonaws.com/info | python -mjson.tool
{
    "languages": {
        "c": {
            "visible_name": "C (gcc)",
            "version": "gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
        },
        "php": {
            "visible_name": "PHP (php5)",
            "version": "PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) (built: Jun 13 2012 17:19:58)"
        },
        "java": {
            "visible_name": "Java (javac)",
            "version": "javac 1.6.0_24"
        },
        "d": {
            "visible_name": "D (dmd)",
            "version": "DMD64 D Compiler v2.060"
        },
        "lua": {
            "visible_name": "Lua (lua)",
            "version": "Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio"
        },
        "c#": {
            "visible_name": "C# (gmcs)",
            "version": "Mono C# compiler version 2.10.8.1"
        },
        "javascript": {
            "visible_name": "Javascript (node)",
            "version": "v0.8.8"
        },
        "ocaml": {
            "visible_name": "OCaml (ocamlc)",
            "version": "3.12.1"
        },
        "perl": {
            "visible_name": "Perl (perl)",
            "version": "This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-gnu-thread-multi"
        },
        "ruby1.8": {
            "visible_name": "Ruby (ruby1.8)",
            "version": "ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]"
        },
        "ruby1.9": {
            "visible_name": "Ruby (ruby1.9)",
            "version": "ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]"
        },
        "haskell": {
            "visible_name": "Haskell (ghc)",
            "version": "The Glorious Glasgow Haskell Compilation System, version 7.4.1"
        },
        "cpp": {
            "visible_name": "C++ (g++)",
            "version": "g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
        },
        "scala": {
            "visible_name": "Scala (scalac)",
            "version": "Scala compiler version 2.9.1 -- Copyright 2002-2011, LAMP/EPFL"
        },
        "go": {
            "visible_name": "Go (go)",
            "version": "go version go1"
        },
        "python": {
            "visible_name": "Python (python)",
            "version": "Python 2.7.3"
        },
        "scheme": {
            "visible_name": "Scheme (plt-r5rs)",
            "version": "Welcome to Racket v5.1.3."
        },
        "bash": {
            "visible_name": "Bash (bash)",
            "version": "GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu)"
        },
        "guile": {
            "visible_name": "Guile (guile)",
            "version": "Guile 1.8.8"
        }
    }
}

Try it out

Hello World, naturally...

$ curl -F source="puts 'hello world'" -F language=ruby1.9 -F stdin="" http://ec2-23-22-253-4.compute-1.amazonaws.com/execute | python -mjson.tool
{
    "error": "",
    "exitstatus": 0,
    "stderr": "",
    "stdout": "hello world\n",
    "time": 1.509106159210205
}

Can I read /etc/passwd?

$ curl -F source="puts File.read('/etc/passwd')" -F language=ruby1.9 -F stdin="" http://ec2-23-22-253-4.compute-1.amazonaws.com/execute | python -mjson.tool
{
    "error": "runtime_error",
    "exitstatus": 1,
    "stderr": "/var/local/straitjacket/tmp/source/hwg6Mzm_jSirNraevni7uerO3bNY1zHsBSx_OlQsnMRa4pU98invfq-U/source.rb:1:in `read': Permission denied - /etc/passwd (Errno::EACCES)\n\tfrom /var/local/straitjacket/tmp/source/hwg6Mzm_jSirNraevni7uerO3bNY1zHsBSx_OlQsnMRa4pU98invfq-U/source.rb:1:in `<main>'\n",
    "stdout": "",
    "time": 0.04093599319458008
}

What about exceeding the time limit?

$ curl -F source="loop {}" -F language=ruby1.9 -F stdin="" http://ec2-23-22-253-4.compute-1.amazonaws.com/execute | python -mjson.tool
{
    "error": "runtime_timelimit",
    "exitstatus": -9,
    "stderr": "",
    "stdout": "",
    "time": 15.516383171081543
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment