0 1 00:00:00,030 --> 00:00:06,000 Again back in the Atom IDE. Let's have a look at creating this object so I 1 2 00:00:06,000 --> 00:00:15,719 just copy the code open and place it in there okay now what we're going to do is 2 3 00:00:15,719 --> 00:00:22,350 that we're going to use the AWS JavaScript SDK for this we're not going 3 4 00:00:22,350 --> 00:00:28,470 to use any of the Cognito stuff and we're going to create a new s3 object 4 5 00:00:28,470 --> 00:00:35,700 and then we're going to call put object and put an object into a location on a 5 6 00:00:35,700 --> 00:00:43,980 bucket so what we need to pass to s3 is we need to pass the bucket name and then 6 7 00:00:43,980 --> 00:00:48,450 to put that object we need to put in these object parameters so those object 7 8 00:00:48,450 --> 00:00:54,149 parameters are going to be in the bucket name which will be back space - lab - 8 9 00:00:54,149 --> 00:00:58,289 picot t it will be different for you of course because s3 bucket names are 9 10 00:00:58,289 --> 00:01:04,860 unique then we need to put in a key now what a key is is simply the location and 10 11 00:01:04,860 --> 00:01:11,790 name of that or the path to that that object when it is uploaded so what we've 11 12 00:01:11,790 --> 00:01:17,460 got here is it's going to be cognito/backspace-academy and then the identity 12 13 00:01:17,460 --> 00:01:26,939 ID of that Cognito user and then it's going to be called test JSON now if you 13 14 00:01:26,939 --> 00:01:32,759 remember from our roll that we created we do have access to Cognito BackSpace 14 15 00:01:32,759 --> 00:01:39,540 Academy and the folder which is in the name or then the identity ID of that 15 16 00:01:39,540 --> 00:01:45,659 user so that a role will allow us to do that so we've got that we've got our 16 17 00:01:45,659 --> 00:01:50,909 object parameters there our content type is going to be a JSON file and the body 17 18 00:01:50,909 --> 00:01:58,290 will be simply an object called test with the key test and we're just going 18 19 00:01:58,290 --> 00:02:02,820 to say it works so it's going to be a JSON object there and we just need to 19 20 00:02:02,820 --> 00:02:09,330 json stringify that data before we send it over to s3 and that's what we do 20 21 00:02:09,330 --> 00:02:12,780 there and that will be the body of our object that's uploaded so what we'll 21 22 00:02:12,780 --> 00:02:16,620 find when we up it will find in that directory Cognito 22 23 00:02:16,620 --> 00:02:21,180 BackSpace Academy and then the identity ID we're going to have a file called 23 24 00:02:21,180 --> 00:02:26,310 test JSON and inside that file will just be a simple test 24 25 00:02:26,310 --> 00:02:32,670 it worked key and value there so when we pass those object parameters to s3 put 25 26 00:02:32,670 --> 00:02:37,190 object will either get an error error or we're going to get a success call there 26 27 00:02:37,190 --> 00:02:42,120 so that's all there is to it I'll just save that and we'll upload that to 27 28 00:02:42,120 --> 00:02:55,560 Amazon s3 and again we make sure that we have public access to that and again we 28 29 00:02:55,560 --> 00:03:04,640 make sure that we clear our browser cache and then refresh our application 29 30 00:03:27,540 --> 00:03:37,170 okay so let's create an s3 object okay so that worked fine we've got the 30 31 00:03:37,170 --> 00:03:40,739 success callback let's have a look and see what happened in the console so 31 32 00:03:40,739 --> 00:03:45,769 what's what's happened here is we've got our test dot JSON has gone to that 32 33 00:03:45,769 --> 00:03:50,120 location in our in our bucket so let's look at the bucket and see what happened 33 34 00:03:50,120 --> 00:03:55,889 just refresh to the screen here okay so now we have which we didn't have before 34 35 00:03:55,889 --> 00:04:00,299 we have a Cognito folder and let's have a look inside that we've got a BackSpace 35 36 00:04:00,299 --> 00:04:06,870 Academy there and we've got another folder in the identity ID of the 36 37 00:04:06,870 --> 00:04:11,040 logged in user so let's have a look at that and we've actually got a test dot 37 38 00:04:11,040 --> 00:04:21,949 JSON let's click on that and let's download it and see what it looks like 38 39 00:04:26,960 --> 00:04:35,159 okay so there we can see we have uploaded a JSON file and it's come up as 39 40 00:04:35,159 --> 00:04:40,800 test for a key and it worked which is exactly what we wanted but of course you 40 41 00:04:40,800 --> 00:04:43,860 can do something more with it you might want to have you know I might create the 41 42 00:04:43,860 --> 00:04:49,740 next Dropbox or whatever and have it so that users can upload files and whatever 42 43 00:04:49,740 --> 00:04:53,969 they want to do so it's all up to you what you want to do with these user 43 44 00:04:53,969 --> 00:05:00,419 credentials okay so that brings us to the end of all of that Cognito stuff 44 45 00:05:00,419 --> 00:05:07,740 what I'm going to do now is that when we ran this code you notice that it took a 45 46 00:05:07,740 --> 00:05:13,529 long time for the JavaScript SDK to come in and that's not something that you 46 47 00:05:13,529 --> 00:05:20,789 really want to do because a JavaScript SDK is quite big it has all of the SDKs 47 48 00:05:20,789 --> 00:05:26,039 for all of the services for AWS so it's really good idea to to really cool that 48 49 00:05:26,039 --> 00:05:31,650 down as much as possible now what I'm going to do is show you how to the 49 50 00:05:31,650 --> 00:05:36,509 technical techniques that we can use to make this load a lot quicker so if 50 51 00:05:36,509 --> 00:05:42,779 you're a reactjs user or developer you're probably quite familiar with web 51 52 00:05:42,779 --> 00:05:48,960 pack I use that quite a bit myself so you can use that to really coal down the 52 53 00:05:48,960 --> 00:05:56,310 size of the of the JavaScript SDK but I'll show you another way that AWS has 53 54 00:05:56,310 --> 00:06:01,710 we can actually build your own version of the AWS JavaScript SDK that will only 54 55 00:06:01,710 --> 00:06:07,969 have the functionality that you require