Date post: | 13-Apr-2017 |
Category: |
Technology |
Upload: | amazon-web-services |
View: | 597 times |
Download: | 0 times |
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
April 2016
Javascript and Node.js Development
Alex Smith
@alexjs / [email protected]
JavaScript
is everywhere.
AWS SDK for
JavaScript in Node.js
AWS SDK for
JavaScript in the
BrowserDesktop or mobile devices
Let’s use them.
Goals
Learn about
AWS SDK for
Node.js
Introduce AWS
SDK for
JavaScript in
the Browser
Write a two-
tiered web
application
AWS SDK for Node.js
Service Coverage
Support for many AWS services
Extensible ClientsCustomize any part of
the request cycle
Standard Node.js Idioms
• Streams
• EventEmitter
• Domains
Open Source
• Apache License, Version
2.0
• https://github.com/aws/aw
s-sdk-js
• Pull requests welcome!
Getting Started:
AWS SDK for Node.js
Installing$ npm install aws-sdk
Bash
Loadingvar AWS = require(‘aws-sdk’);
JS
Configuring the SDKAWS.config
• Credentials*
• Region*
• Extras
* Required by the SDK
Configuring Credentials• IAM roles for EC2
Instances
• Environment Variables
• File System (outside
source control)
Do Not Hardcode Credentials
Unless they are read-only and scoped to specific resources.
IAM Roles for EC2 Instances
=Zero Configuration
Configuration Items• AWS_ACCESS_KEY_ID
• AWS_SECRET_ACCESS_KEY
• AWS_REGION*
Configuration:
Region and Extras
AWS.config.update({
region: ‘ap-southeast-1’, // AWS_REGION
maxRetries: 10, // default: 3
logger: process.stdout,
// ... more options ...
});
JS
Config From a File
AWS.config.loadFromPath(‘./config.json’);
JS
If this file contains credentials, keep it out of source control
Working with Services
Service ObjectsAWS.S3
AWS.EC2
AWS.DynamoDB
AWS.SQS
AWS.SNS
...
Constructing a Service Object
var ec2 = new AWS.EC2([config]);
JS
Calling an Operation
ec2.describeInstances(params, callback);
JS
The Callback
function (err, data) { ... }
JS
Getting a Request Object
var req = ec2.describeInstances(params);
JS
Sending the Request Object
var resp = req.send(callback);
JS
Adding Listeners
to the Request Object
req.on(‘complete’, function(resp) { ... });
JS
The Request Cycle
Send AWS.Request
Get AWS.Response
AWS.Request
Operation
AWS.Response
build sign send
complete
success
error
Emitted Lifecycle Events
... ... ...
Request Lifecycle
callbacksend()
AWS.Request
.send(callback)
.on(event, callback)
.httpRequest
...
AWS.Response
.error
.data
.retryCount
.httpResponse
...
Request Lifecycle Recap
• Send AWS.Request
• Emits Lifecycle
Events
• Callback with
AWS.Response
Features of the SDK
Features
Global Configuration Object
Bound Parameters
Response Pagination
Event Listeners (Per-Service and Global)
API Version Locking
Secure Credential Management
Demo
AWS SDK
for JavaScript
in the Browser
HTMLGetting the SDK
<script src=”https://sdk.amazonaws.com/js/aws-sdk-2.3.5.min.js” />
Many Supported ServicesS3
DynamoDB
SQS
SNS
STS
Kinesis
Lambda
…
Default: all services that support CORS
All Modern Browsers
28.0+ 23.0+ 10+ 17.0+ 5.1+
Usage is the same.
But in your browser, or mobile
device
Configuration is different.
Why?
Two-Tier Web Applications
Traditional Application Architecture
Other ServicesNode.js Backend
Your Services
Two-Tier Application Architecture
Your Services
SDK on the Device
Benefits
• Fewer moving parts
• Easy prototyping
• Deploying as simple as
copying files to Amazon
S3
• Fully dynamic app for
pennies a month
Next Level Web Apps
App
Ideas
Forum Software
Blog Commenting Service
Blogging Platform
Firefox/Chrome Extensions
WinRT (Metro Style) Apps
Any Mobile App!
Let’s Look at a Web
Application
Using nothing but
HTML, CSS, and JavaScript
A Simple Blog
• Content stored in Amazon
DynamoDB
• Assets in Amazon S3
• Lambda Function
• We don’t have it in now,
but using Lambda to
take a thumbnail
AWS Javascript SDKfor the browser
Amazon DynamoDBUnlimited size and
throughput Database
Amazon S3Unlimited Storage &
Web Service
AWS LambdaUnlimited Cloud Functions
Function: Create Thumbnailfor new files in S3
Demo – Serverless Solution at Any Scale
FacebookAuthentication
Demo
Contribute to the SDK
Improve Documentation
Report Issues
Submit Pull Requests
Open Source
Third Party Plugins
Great way to easily add features
Node.js
Please, write More!