Writing JavaScript Applications with the AWS SDK (TLS303) | AWS re:Invent 2013

3,340 views

Published on

We give a guided tour of using the AWS SDK for JavaScript to create powerful web applications. Learn the best practices for configuration, credential management, streaming requests, as well as how to use some of the higher level features in the SDK. We also show a live demonstration of using AWS services with the SDK to build a real-world JavaScript application.

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,340
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
67
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Writing JavaScript Applications with the AWS SDK (TLS303) | AWS re:Invent 2013

  1. 1. Writing JavaScript Applications with the AWS SDK by Loren Segal November 15th, 2013 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc. Wednesday, November 27, 13
  2. 2. JavaScript is everywhere. Wednesday, November 27, 13
  3. 3. AWS SDK for JavaScript in Node.js Almost a year old! Wednesday, November 27, 13
  4. 4. AWS SDK for JavaScript in the Browser Desktop or mobile devices Wednesday, November 27, 13
  5. 5. Let’s use them. Wednesday, November 27, 13
  6. 6. Goals Wednesday, November 27, 13
  7. 7. 1. Learn about AWS SDK for Node.js Goals Wednesday, November 27, 13
  8. 8. 1. Learn about AWS SDK for Node.js Goals Wednesday, November 27, 13 2. Introduce AWS SDK for JavaScript in the Browser
  9. 9. 1. Learn about AWS SDK for Node.js Goals 2. Introduce AWS SDK for JavaScript in the Browser 3. Write a two-tiered web application using JavaScript, HTML, and CSS Wednesday, November 27, 13
  10. 10. AWS SDK for Node.js Wednesday, November 27, 13
  11. 11. Full Service Coverage Support for over 30 AWS services Wednesday, November 27, 13
  12. 12. Extensible Clients Customize any part of the request cycle Wednesday, November 27, 13
  13. 13. Standard Node.js Idioms Streams, EventEmitter, Domains Wednesday, November 27, 13
  14. 14. Open Source Apache License, Version 2.0 http://github.com/aws/aws-sdk-js Wednesday, November 27, 13
  15. 15. Getting Started AWS SDK for Node.js Wednesday, November 27, 13
  16. 16. Installing Bash $ npm install aws-sdk Wednesday, November 27, 13
  17. 17. Loading JS var AWS = require(‘aws-sdk’); Wednesday, November 27, 13
  18. 18. Configuring the SDK AWS.config Wednesday, November 27, 13
  19. 19. Configuring the SDK Credentials * AWS.config * Required by the SDK Wednesday, November 27, 13
  20. 20. Configuring the SDK Credentials * Region * AWS.config * Required by the SDK Wednesday, November 27, 13
  21. 21. Configuring the SDK AWS.config Credentials * Region * Extras * Required by the SDK Wednesday, November 27, 13
  22. 22. Configuring Credentials Wednesday, November 27, 13
  23. 23. Configuring Credentials Wednesday, November 27, 13 IAM roles for EC2 Instances
  24. 24. Configuring Credentials Wednesday, November 27, 13 IAM roles for EC2 Instances Environment Variables
  25. 25. Configuring Credentials Wednesday, November 27, 13 IAM roles for EC2 Instances Environment Variables File System (outside source control)
  26. 26. Do Not Hardcode Credentials Unless they are read-only and scoped to specific resources. Wednesday, November 27, 13
  27. 27. IAM Roles for EC2 Instances = Zero Configuration Wednesday, November 27, 13
  28. 28. Environment Variables AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION* Wednesday, November 27, 13
  29. 29. Configuring Region and Extras Wednesday, November 27, 13
  30. 30. JS AWS.config.update({ region: ‘us-west-2’, // AWS_REGION maxRetries: 10, // default: 3 logger: process.stdout, // ... more options ... }); Wednesday, November 27, 13
  31. 31. Config From a File JS AWS.config.loadFromPath(‘./config.json’); If this file contains credentials, keep it out of source control Wednesday, November 27, 13
  32. 32. Working with Services Wednesday, November 27, 13
  33. 33. Service Objects Wednesday, November 27, 13
  34. 34. AWS.S3 Service Objects Wednesday, November 27, 13
  35. 35. Service Objects Wednesday, November 27, 13 AWS.S3 AWS.EC2
  36. 36. Service Objects Wednesday, November 27, 13 AWS.S3 AWS.EC2 AWS.DynamoDB
  37. 37. Service Objects Wednesday, November 27, 13 AWS.S3 AWS.EC2 AWS.DynamoDB AWS.SQS
  38. 38. Service Objects Wednesday, November 27, 13 AWS.S3 AWS.EC2 AWS.DynamoDB AWS.SQS AWS.SNS
  39. 39. Service Objects Wednesday, November 27, 13 AWS.S3 AWS.EC2 AWS.DynamoDB AWS.SQS AWS.SNS ...
  40. 40. Constructing a Service Object JS var ec2 = new AWS.EC2([config]); Wednesday, November 27, 13
  41. 41. Calling an Operation JS ec2.describeInstances(params, callback); Wednesday, November 27, 13
  42. 42. The Callback JS function (err, data) { ... } Wednesday, November 27, 13
  43. 43. Getting a Request Object JS var req = ec2.describeInstances(params); Wednesday, November 27, 13
  44. 44. Sending the Request Object JS var resp = req.send(callback); Wednesday, November 27, 13
  45. 45. Adding Listeners to the Request Object JS req.on(‘complete’, function(resp) { ... }); Wednesday, November 27, 13
  46. 46. The Request Cycle Wednesday, November 27, 13
  47. 47. Send AWS.Request Get AWS.Response Wednesday, November 27, 13
  48. 48. Request Lifecycle Wednesday, November 27, 13
  49. 49. Request Lifecycle Operation Wednesday, November 27, 13
  50. 50. Request Lifecycle Operation Wednesday, November 27, 13
  51. 51. Request Lifecycle Operation AWS.Request Wednesday, November 27, 13
  52. 52. Request Lifecycle Operation send() AWS.Request Wednesday, November 27, 13
  53. 53. Request Lifecycle Emitted Lifecycle Events Operation send() AWS.Request Wednesday, November 27, 13 complete success build ... sign ... send ... error
  54. 54. Request Lifecycle Emitted Lifecycle Events Operation send() AWS.Request Wednesday, November 27, 13 complete success build ... sign ... send ... error callback
  55. 55. Request Lifecycle Emitted Lifecycle Events Operation send() AWS.Request Wednesday, November 27, 13 complete success build ... sign ... send ... error callback AWS.Response
  56. 56. AWS.Request Wednesday, November 27, 13
  57. 57. .send(callback) AWS.Request Wednesday, November 27, 13
  58. 58. AWS.Request Wednesday, November 27, 13 .send(callback) .on(event, callback)
  59. 59. AWS.Request Wednesday, November 27, 13 .send(callback) .on(event, callback) .httpRequest
  60. 60. AWS.Request Wednesday, November 27, 13 .send(callback) .on(event, callback) .httpRequest ...
  61. 61. AWS.Response Wednesday, November 27, 13
  62. 62. .error AWS.Response Wednesday, November 27, 13
  63. 63. .error .data AWS.Response Wednesday, November 27, 13
  64. 64. AWS.Response Wednesday, November 27, 13 .error .data .retryCount
  65. 65. AWS.Response Wednesday, November 27, 13 .error .data .retryCount .httpResponse
  66. 66. AWS.Response Wednesday, November 27, 13 .error .data .retryCount .httpResponse ...
  67. 67. Request Lifecycle Recap Wednesday, November 27, 13
  68. 68. Request Lifecycle Recap Wednesday, November 27, 13 Send AWS.Request
  69. 69. Request Lifecycle Recap Wednesday, November 27, 13 Send AWS.Request Emits Lifecycle Events
  70. 70. Request Lifecycle Recap Wednesday, November 27, 13 Send AWS.Request Emits Lifecycle Events Callback with AWS.Response
  71. 71. Features of the SDK Wednesday, November 27, 13
  72. 72. SDK Features Wednesday, November 27, 13
  73. 73. Global Configuration Object SDK Features Wednesday, November 27, 13
  74. 74. SDK Features Wednesday, November 27, 13 Global Configuration Object Bound Parameters
  75. 75. SDK Features Wednesday, November 27, 13 Global Configuration Object Bound Parameters Response Pagination
  76. 76. SDK Features Wednesday, November 27, 13 Global Configuration Object Bound Parameters Response Pagination Event Listeners (Per-Service and Global)
  77. 77. SDK Features Wednesday, November 27, 13 Global Configuration Object Bound Parameters Response Pagination Event Listeners (Per-Service and Global) API Version Locking
  78. 78. SDK Features Wednesday, November 27, 13 Global Configuration Object Bound Parameters Response Pagination Event Listeners (Per-Service and Global) API Version Locking Secure Credential Management
  79. 79. AWS SDK for JavaScript in the Browser Wednesday, November 27, 13
  80. 80. Developer Preview Looking for Feedback Wednesday, November 27, 13
  81. 81. Getting the SDK language <script src=”https://sdk.amazonaws.com/js/aws-sdk-2.0.0-rc1.min.js” /> Wednesday, November 27, 13
  82. 82. 5 Supported Services Wednesday, November 27, 13
  83. 83. Amazon S3 5 Supported Services Wednesday, November 27, 13
  84. 84. 5 Supported Services Wednesday, November 27, 13 Amazon S3 Amazon DynamoDB
  85. 85. 5 Supported Services Wednesday, November 27, 13 Amazon S3 Amazon DynamoDB Amazon SQS
  86. 86. 5 Supported Services Wednesday, November 27, 13 Amazon S3 Amazon DynamoDB Amazon SQS Amazon SNS
  87. 87. 5 Supported Services Wednesday, November 27, 13 Amazon S3 Amazon DynamoDB Amazon SQS Amazon SNS STS
  88. 88. All Modern Browsers 28.0+ Wednesday, November 27, 13 23.0+ 10+ 17.0+ 5.1+
  89. 89. Usage is the same. But in your browser or mobile device Wednesday, November 27, 13
  90. 90. Configuration is Different Wednesday, November 27, 13
  91. 91. Why is it different? Two-Tier Web Applications Wednesday, November 27, 13
  92. 92. Traditional Application Architecture Your Services nodeJS Node.js Backend Wednesday, November 27, 13 Other Services
  93. 93. Two-Tier Application Architecture nodeJS SDK on the Device nodeJS Your nodeJS Wednesday, November 27, 13 Services
  94. 94. Benefits Wednesday, November 27, 13
  95. 95. Fewer moving parts Benefits Wednesday, November 27, 13
  96. 96. Fewer moving parts Easy prototyping Benefits Wednesday, November 27, 13
  97. 97. Benefits Wednesday, November 27, 13 Fewer moving parts Easy prototyping Deploying as simple as copying files to Amazon S3
  98. 98. Benefits Wednesday, November 27, 13 Fewer moving parts Easy prototyping Deploying as simple as copying files to Amazon S3 Fully dynamic app for pennies a month
  99. 99. Next Level Web Apps Wednesday, November 27, 13
  100. 100. App Ideas Wednesday, November 27, 13
  101. 101. Forum Software App Ideas Wednesday, November 27, 13
  102. 102. App Ideas Wednesday, November 27, 13 Forum Software Blog Commenting Service
  103. 103. App Ideas Wednesday, November 27, 13 Forum Software Blog Commenting Service Blogging Platform
  104. 104. App Ideas Wednesday, November 27, 13 Forum Software Blog Commenting Service Blogging Platform Firefox/Chrome Extensions
  105. 105. App Ideas Wednesday, November 27, 13 Forum Software Blog Commenting Service Blogging Platform Firefox/Chrome Extensions WinRT (Metro Style) Apps
  106. 106. App Ideas Wednesday, November 27, 13 Forum Software Blog Commenting Service Blogging Platform Firefox/Chrome Extensions WinRT (Metro Style) Apps Any Mobile App!
  107. 107. Let’s Look at a Web Application Using nothing but HTML, CSS, and JavaScript Wednesday, November 27, 13
  108. 108. A Simple Blog Content stored in Amazon DynamoDB Assets in Amazon S3 Wednesday, November 27, 13
  109. 109. Key Differences Three-Tier to Two-Tier Wednesday, November 27, 13
  110. 110. Key Differences Three-Tier to Two-Tier Wednesday, November 27, 13 Browser Security
  111. 111. Key Differences Three-Tier to Two-Tier Wednesday, November 27, 13 Browser Security CORS in the browser Credentials on device
  112. 112. Cross-Origin Resource Sharing Wednesday, November 27, 13
  113. 113. CORS Wednesday, November 27, 13
  114. 114. CORS Wednesday, November 27, 13 Browser sends pre-flight request to external host.
  115. 115. CORS Wednesday, November 27, 13 Browser sends pre-flight request to external host. Host acknowledges browser.
  116. 116. CORS Wednesday, November 27, 13 Browser sends pre-flight request to external host. Host acknowledges browser. Browser sends XHR request.
  117. 117. CORS + S3 Wednesday, November 27, 13
  118. 118. CORS + S3 Wednesday, November 27, 13 CORS needs special configuration on Amazon S3.
  119. 119. CORS + S3 Wednesday, November 27, 13 CORS needs special configuration on Amazon S3. Configure CORS with bucket policy.
  120. 120. Configuring CORS on Amazon S3 Wednesday, November 27, 13
  121. 121. Getting Credentials Onto Your Device Wednesday, November 27, 13
  122. 122. Getting Credentials Onto Your Device Wednesday, November 27, 13
  123. 123. Getting Credentials Onto Your Device Wednesday, November 27, 13 Never hardcode credentials
  124. 124. Getting Credentials Onto Your Device Wednesday, November 27, 13 Never hardcode credentials Use Web Identity Federation
  125. 125. Web Identity Federation Use Facebook, Google, or Login with Amazon as third-party identity providers Wednesday, November 27, 13
  126. 126. Web Identity Federation Set up IAM roles for these identity providers Wednesday, November 27, 13
  127. 127. 1 2 3 Wednesday, November 27, 13
  128. 128. Web Identity Federation Set up permissions for IAM role Wednesday, November 27, 13
  129. 129. AWS.WebIdentityCredentials JS AWS.config.credentials = new AWS.WebIdentityCredentials({ RoleArn: ‘arn:aws:iam::<ACCOUNT_ID>:role/<ROLE_NAME>’, ProviderId: ‘graph.facebook.com’, WebIdentityToken: fbAccessToken }); Wednesday, November 27, 13
  130. 130. Get a Facebook Access Token JS // 1. Load the FB JS SDK // 2. Call FB.login() FB.login(function (response) { if (response.authResponse) { fbAccessToken = response.authResponse.accessToken; AWS.config.credentials = new AWS.WebIdentityCredentials({...}); }); Wednesday, November 27, 13
  131. 131. Same Concept For other identity providers Wednesday, November 27, 13
  132. 132. Our Community Wednesday, November 27, 13
  133. 133. We ♥ Open Source Wednesday, November 27, 13
  134. 134. https://github.com/ aws/aws-sdk-js Wednesday, November 27, 13
  135. 135. Contributing to the SDK Wednesday, November 27, 13
  136. 136. Contributing to the SDK Wednesday, November 27, 13 Improve Documentation
  137. 137. Contributing to the SDK Wednesday, November 27, 13 Improve Documentation Report Issues
  138. 138. Contributing to the SDK Wednesday, November 27, 13 Improve Documentation Report Issues Submit Pull Requests
  139. 139. Contributing to the SDK Wednesday, November 27, 13 Improve Documentation Report Issues Submit Pull Requests Third-Party Plugins
  140. 140. Third Party Plugins A great way to add features Wednesday, November 27, 13
  141. 141. Node.js Wednesday, November 27, 13
  142. 142. Wednesday, November 27, 13
  143. 143. Write More! Wednesday, November 27, 13
  144. 144. Please give us your feedback on this presentation TLS303 As a thank you, we will select prize winners daily for completed surveys! Wednesday, November 27, 13 Thank You

×