Kong / lua-resty-aws

AWS SDK for OpenResty
https://kong.github.io/lua-resty-aws/topics/README.md.html
Apache License 2.0
23 stars 25 forks source link

Can you provide an example of getting the aws s3 object using the TokenFileWebIdentityCredentials approach? #124

Open winsomely opened 1 month ago

winsomely commented 1 month ago

Can you provide an example of getting the aws s3 object using the TokenFileWebIdentityCredentials approach?

windmgc commented 1 month ago

Hi, @winsomely

TokenFileWebIdentityCredential is an implementation of fetching IAM credentials in the EKS environment with "IAM role for service account" enabled. Typically you don't need to call it directly

If you're running your openresty program inside the EKS environment with IRSA enabled, you can do something simple as follows:

-- in the "init" phase initialize the configuration
local _ = require("resty.aws.config").global

-- In your code
local AWS = require("resty.aws")
local AWS_global_config = require("resty.aws.config").global

local config = { region = AWS_global_config.region }

local aws = AWS(config)

local s3 = aws:S3()

-- Invoke a method.
local results, err = s3:getObject {
  Bucket = "my-bucket",
  Key = "my-key",
}