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