hxAwsSdk
Overview
This is a cross platform haxe library that provides access to AWS.
Goals
- wide SDK coverage
- minimal client code
- strongly typed requests and responses
- consistent interface across JSON and XML services
Usage
Setup
The following steps will get this library installed and configured to generate aws clients for your project as part of your build.
-
install this library
haxelib install hxAwsSdk -
create a config file in your project directory containing one entry per line formatted as
serviceName:operation. whereserviceNamematches a directory in botocore, andoperationmatches the operation name from that service'sservice.jsonfile. For example this is where cognito-idp:ListUsers comes from, and this is what a config file might look like:cognito-idp:ListUsers dynamodb:ListTables dynamodb:Query s3:GetObject s3:GetBucketVersioning ssm:GetParameter -
add a command to the top of your build to generate the aws clients. the arguments are described in the Generator Args section below.
-cmd haxelib run hxAwsSdk ../../python/botocore config/awssdk.conf src-gen --next -
add the generated files to your build
-cp src-gennote that
src-genwas the generator output directory from the command in step 2. -
add this library to your build
-lib hxAwsSdk -
Generator Args
There are three arguments that must be passed to the generator. This is the command:
haxelib run hxAwsSdk [path-to-botocore] [config-file] [output-dir]where
- path-to-botocore: absolute or relative path to these files on your local filesystem
- config-file: the relative path to the file you created in Usage Step 1
- output-dir: the relative path to where you want the generator to write to
Workflow
The docs for the AWS APIs and boto3 are relevant but in order to see the exact naming and capitalization of the haxe request and response types it is best to generate the types for your project and refer to the generated client sources. All needed types are added to the client file for the respective AWS service.
API Coverage
Since this library generates the client code from API definitions the actual API coverage should be much more than what I've tested and it's hard to know how much of the total API is covered. Some of the APIs I've tested are listed in awssdk.conf I'm not aware of any APIs that aren't covered.
Examples
The following code examples show how to use the generated clients to access AWS. Examine the generated client files to see the exact method names, input names, and output types for each operation.
-
Dynamo DB
List tables in the account:
import awssdk.DynamoDBClient; ... var dynamodb = new DynamoDBClient(REGION); var ret :ListUsersResponse = dynamodb.listTables({}); -
S3
List objects in a bucket:
import awssdk.S3Client; ... var s3 = new S3Client(REGION); var ret :ListObjectsV2Output = s3.listObjectsV2({ "OptionalObjectAttributes": [], "Bucket": "my-bucket" });Presign a URL:
import awssdk.AwsSdk; ... var presignedUrl = awsSdk.presignUrl({ "protocol": "rest-xml", "serviceName": "S3", "httpMethod": "GET", "region": "us-east-1", "hostPrefix": "s3", "requestUri": "/my-bucket/my-key", }); -
Systems Manager
Get a parameter:
import awssdk.SSMClient; ... var ssm = new SSMClient(REGION); var ret : = ssm.getParameter({ "Name": "/scope/parametername" });