Skip to content

A declarative library for application development using Cloud services with JavaScript

License

Notifications You must be signed in to change notification settings

duyoji/aws-amplify

 
 

Repository files navigation

AWS Amplify

AWS Amplify is a JavaScript library for frontend and mobile developers building cloud-enabled applications. The library is a declarative interface across different categories of operations in order to make common tasks easier to add into your application. The default implementation works with Amazon Web Services (AWS) resources but is designed to be open and pluggable for usage with other cloud services that wish to provide an implementation or custom backends.

Installation

Web Development

AWS Amplify is available as the aws-amplify package on npm

npm install aws-amplify

If you are developing a React app, you can install an additional package aws-amplify-react containing Higher Order Components:

npm install aws-amplify-react

React Native Development

For React Native development, install aws-amplify-react-native instead of aws-amplify

npm install aws-amplify-react-native

You will need to link libraries in your project for the Auth module on React Native. Follow the instructions here.

Documentation

Examples

AWS Amplify supports many category scenarios such as Auth, Analytics, APIs and Storage as outlined in the Developer Guide. A couple of samples are below.

1. Collect user session metrics

By default, AWS Amplify can send user session information as metrics with a few lines of code:

import Amplify, { Analytics } from 'aws-amplify';
import aws_exports from './aws-exports';

Amplify.configure(aws_exports);

2. Add Authentication to your App

Take a fresh React app created by create-react-app as an example and edit the App.js file:

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

import Amplify from 'aws-amplify';
import { withAuthenticator } from 'aws-amplify-react';
import aws_exports from './aws-exports';

Amplify.configure(aws_exports);

class App extends Component {
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to React</h1>
        </header>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
      </div>
    );
  }
}

export default withAuthenticator(App);

3. Sign HTTP requests

Sign REST requests with AWS Signature Version 4 using the API module to one or multiple endpoints:

let apiName = 'MyApiName';
let path = '/path'; 
let options = {
    headers: {...} // OPTIONAL
}
API.get(apiName, path, options).then(response => {
    // Add your code here
});

4. Upload/Download public or private content

With configurable settings, store content in an S3 bucket in public folders for all of your application's users or in private folders for each user identity:

  Storage.put(key, fileObj, {level: 'private'})
        .then (result => console.log(result))
        .catch(err => console.log(err));
        
    // Stores data with specifying its MIME type
    Storage.put(key, fileObj, {
        level: 'private',
        contentType: 'text/plain'
    })
    .then (result => console.log(result))
    .catch(err => console.log(err));

About

A declarative library for application development using Cloud services with JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 57.5%
  • JavaScript 23.0%
  • TypeScript 14.7%
  • CSS 4.8%