DEPRECATED! Please either use the AWS Native SDK plugin by Osei Fortune, or try
nativescript-nodeify
(which allows you to use the ASW JS SDK) and follow these instructions.
A. Because you can't due to dependencies on Node and/or the browser (crypto, path, DOMParser, etc). Both of which are not available in a NativeScript context.
A. Oh yes it is but upon installation the plugin will modify a few bits in the AWS SDK so it's NativeScript-compatible.
A. The main trick here is a postinstall
hook that scans the aws-sdk
module for package.json
files,
looks for browser
configuration nodes, and find-replaces any matching require()
calls in that package and its dependencies.
A. Not in this case, at least not without further modifications. Feel free to submit a PR for a nicer implementation, but this is the best I could think of.
A. Thanks. And good point. Most of this should apply to more generic usages so expect me to release some universal plugin this one will depend on.
From the command prompt go to your app's root folder and execute:
tns plugin add nativescript-aws
Make sure you use TypeScript (as our demo app does), because this plugin exposes the AWS SDK's TypeScript definitions so you'll have an easier time interacting with Amazon's services.
Really, check the demo! It shows how to interact with S3 and Dynamo, but you should be able to interact with all other AWS services as well.
Run the demo app from the root of the project: npm run demo.ios
or npm run demo.android
.
100% equal to the aws-sdk
module. Look at their docs and use TypeScript to make your life easier.
To get you started, this is how you can require the plugin and pass your credentials:
import * as AWS from "nativescript-aws";
import { Credentials } from "nativescript-aws";
AWS.config.update({
region: AWS_region,
credentials: new Credentials(AWS_accessKeyId, AWS_secretAccessKey)
});
var AWS = require("nativescript-aws");
AWS.config.update({
region: AWS_region,
credentials: {
accessKeyId: AWS_accessKeyId,
secretAccessKey: AWS_secretAccessKey
}
});
I've tried to iron out all compatibility issues between AWS and NativeScript,
but you may use some service that throws an error at runtime because it's require
-ing some
unsupported node module. Please open an issue in that case and I'll take a look!
Working on a way to make NativeScript with virtually any Node module, inspired by this plugin.. will update this doc when more news is available.