Giter VIP home page Giter VIP logo

aws-lua's Introduction

aws-lua

This small poc creates aws resources from lua.

For example, the following script list all vpc and look for a vpc with the tag myvpc=true. If such a vpc is not found, it will create one:

local aws = require("aws")
-- Look for a VPC with the tag myvpc=true.
-- If not found create one with cidr=10.0.0.0/16

-- create vpc
local function create_vpc(cidr, tags)
    vpc = {
        cidr = cidr,
    }
    if tags ~= nil and type(tags) == "table" then
        vpc["tags"] = tags
    end
    return aws.create("aws_vpc", vpc)
end

-- Get VPCs
local vpcs, err = aws.list("aws_vpc", {})
if err ~= nil then
    print(err)
    os.exit(1)
end

local vpc = { found = false }
if vpcs ~= nil then
    for _, _vpc in pairs(vpcs.Vpcs) do
        if _vpc.Tags ~= nil then
            for _, v in pairs(_vpc.Tags) do
                if v.Key == "myvpc" and v.Value == "true" then
                    vpc.found = true
                    vpc.id = _vpc.VpcId
                end
            end
        end
    end
end

local vpc_id
if vpc.found then
    print("myvpc VPC found. ID: " .. vpc.id)
    vpc_id = vpc.id
else
    local vpc, err = create_vpc("10.0.0.0/16", { myvpc = "true" })
    if err ~= nil then
        print("vpc creation failed: " .. err)
        os.exit(1)
    end
    if vpc ~= nil then
        print("vpc created: " .. vpc.Vpc.VpcId)
        vpc_id = vpc.Vpc.VpcId
    end
end

Use

make build
bin/aws-lua -f path_to_lua_script --aws-access-key <access-key> --aws-secret-key <secret-key> --aws-region <aws-region>

Current supported AWS API:

  • DescribeAvailabilityZones
  • CreateVpc
  • DescribeVpcs
  • CreateSubnet
  • DescribeSubnets
  • CreateUser
  • ListUsers
  • CreateAccessKey
  • ListAccessKeys

aws-lua's People

Contributors

tupyy 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.