Giter Site home page Giter Site logo

lua-resty-aws's Introduction

lua-resty-aws

AWS ACM and S3 for OpenResty + Lua

Overview

This library implements request signing using the AWS Signature Version 4 specification. This signature scheme is used by nearly all AWS services.

Installation

This package require some other packages

sudo luarocks install luasec
sudo luarocks install lua-json
sudo luarocks install lua-erento-hmac
sudo luarocks install lua-resty-string
sudo luarocks install xml2lua

git clone https://github.com/namndbka/lua-resty-aws.git
cp -R lua-resty-aws/lib/resty <your_lua_lib_path>

Usage

Currently, this library support some method of aws acm and aws s3.

acm

local json = require "json"
local aws_acm = require "resty.aws-acm"

local config = {
    aws_key        = "<AWS_KEY>",
    aws_secret     = "<AWS_SECRET_KEY>",
    aws_region     = "<AWS_REGION>",
    user_agent     = "<YOUR_AGENT>"
  }

function demo_cert()
  local acm = aws_acm:new(config)
  local list_cert, status = acm:list_certificates()
  ngx.log(ngx.INFO, 'status: ', status)
  local list_o = json.decode(list_cert)
  local listArrs = list_o["CertificateSummaryList"]
  local cert_arn = nil
  for i = 1, table.getn(listArrs) do 
    if(listArrs[i]["DomainName"] == "*.example.com") then
      cert_arn = listArrs[i]["CertificateArn"]
      break
    end
  end
  if (cert_arn ~= nil) then
    ngx.say("==== GET CERTIFICATE ====")
    local get_cert, status1 = acm:get_certificate(cert_arn)
    ngx.say(get_cert)
    ngx.say("==== DESCRIBE CERTIFICATE ====")
    local des_cert, status2 = acm:describe_certificate(cert_arn)
    ngx.say(des_cert)
  end
end

local ac = demo_cert()

s3

local json = require "json"
local aws_s3 = require "resty.aws-s3"

local config = {
    aws_key        = "<AWS_KEY>",
    aws_secret     = "<AWS_SECRET_KEY>",
    aws_region     = "<AWS_REGION>",
    user_agent     = "<YOUR_AGENT>"
}
local s3 = aws_s3:new(config)
local buckets, status = s3:list_buckets()
ngx.log(ngx.INFO, "list_buckets status: ", status)
if(buckets ~= nil) then
    for k, p in pairs(buckets.Buckets) do
        for i = 1, table.getn(p) do
            ngx.say(json.encode(p[i]))
        end
    end
end

 -- get all objects in bucket `bucket_name`
local objects, status = s3:list_objects('bucket_name')
ngx.log(ngx.INFO, "list_objects status: ", status)
if(objects ~= nil) then
    for i, p in pairs(objects.Contents) do
        ngx.say(json.encode(p))
    end
end
local cres, status = s3:create_bucket('bucket_name')
ngx.log(ngx.INFO, "create_bucket status: ", status)
ngx.say(cres)

local file, status = s3:download_file('bucket_name', 'key')
ngx.log(ngx.INFO, "download_file status: ", status)

Note: you have to set either s3- or s3 as subdomain of amazonaws.com depending on your need. s3 will use us-east-1 region.

Link Resource

lua-resty-aws's People

Contributors

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