Skip to content

Instantly share code, notes, and snippets.

@chochinlu
Last active August 21, 2018 03:20
Show Gist options
  • Save chochinlu/0323a0f2d2e8cc9d4539afa02d1a7044 to your computer and use it in GitHub Desktop.
Save chochinlu/0323a0f2d2e8cc9d4539afa02d1a7044 to your computer and use it in GitHub Desktop.
aws-sdk ReasonML binding testing.
const AWS = require("aws-sdk");
const credentials = new AWS.SharedIniFileCredentials({
profile: "xxx-dev"
});
AWS.config.credentials = credentials;
const LAMBDA_REGION = "ap-southeast-1";
AWS.config.update({ region: LAMBDA_REGION });
const params = {
limit: 2
// logGroupNamePrefix: '',
};
const cloudwatchlogs = new AWS.CloudWatchLogs({ apiVersion: "2014-03-28" });
cloudwatchlogs.describeLogGroups(params, (err, data) => {
if (err) console.log(err, err.stack);
else console.log(data);
});
type credentialObj = {. "profile": string};
[@bs.deriving abstract]
type awsConfig = {mutable credentials: credentialObj};
type aws = {. config: awsConfig};
[@bs.obj]
external makeCredentialObj : (~profile: string) => credentialObj = "";
[@bs.module "aws-sdk"] [@bs.new]
external sharedIniFileCredentials : credentialObj => credentialObj =
"SharedIniFileCredentials";
let c = makeCredentialObj(~profile="xxxx-dev") |> sharedIniFileCredentials;
/* AWS.config.credentials = credentials; */
[@bs.val] [@bs.scope "AwsSdk"] external config : awsConfig = "";
config |. credentialsSet(c);
type regionObj = {. "region": string};
[@bs.obj] external makeRegionObj : (~region: string) => regionObj = "";
[@bs.module "aws-sdk"] [@bs.scope "config"]
external update : regionObj => aws = "";
let s_LAMBDA_REGION = "ap-southeast-1";
makeRegionObj(~region=s_LAMBDA_REGION) |> update;
type watchlogObj = {. "apiVersion": string};
[@bs.obj]
external makeWatchlogObj : (~apiVersion: string, unit) => watchlogObj = "";
[@bs.module "aws-sdk"] [@bs.new]
external cloudWatchLogs : watchlogObj => aws = "CloudWatchLogs";
let logsAction =
makeWatchlogObj(~apiVersion="2014-03-28", ()) |> cloudWatchLogs;
Js.log(logsAction);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment