1 00:00:00,240 --> 00:00:01,260 ‫So, let's get started 2 00:00:01,260 --> 00:00:03,140 ‫with the AppSync service. 3 00:00:03,140 --> 00:00:08,140 ‫So, AppSync is going to be used to get a GraphQL API on AWS 4 00:00:08,410 --> 00:00:12,030 ‫but this also gets you offline synchronization for data 5 00:00:12,030 --> 00:00:15,150 ‫and also real-time updates through WebSockets. 6 00:00:15,150 --> 00:00:17,270 ‫Okay, let's create an API, you know different ways 7 00:00:17,270 --> 00:00:20,430 ‫of creating the API, we can either use DynamoDB 8 00:00:20,430 --> 00:00:23,610 ‫with a wizard with DynomoDB table or start from scratch, 9 00:00:23,610 --> 00:00:25,950 ‫but we'll be using a sample project 10 00:00:25,950 --> 00:00:27,810 ‫and this one we have different options. 11 00:00:27,810 --> 00:00:30,410 ‫We have the EventApp, the ChatApp, the TaskApp, 12 00:00:30,410 --> 00:00:32,070 ‫or the BlogApp, okay? 13 00:00:32,070 --> 00:00:33,290 ‫And as we can see each 14 00:00:33,290 --> 00:00:36,120 ‫of these apps has a different kind of twist. 15 00:00:36,120 --> 00:00:38,260 ‫So, this one is very simple. 16 00:00:38,260 --> 00:00:40,210 ‫This one uses Cognito User Pools, 17 00:00:40,210 --> 00:00:41,680 ‫this one will use AWS Lambda 18 00:00:41,680 --> 00:00:44,560 ‫to get data into an Amazon RDS database, 19 00:00:44,560 --> 00:00:46,640 ‫and this one will have the real-time WebSockets 20 00:00:46,640 --> 00:00:50,120 ‫application in the ChatApp, we'll keep it very, very simple 21 00:00:50,120 --> 00:00:51,990 ‫and use the EventApp for now. 22 00:00:51,990 --> 00:00:53,470 ‫So, we'll go with the EventApp 23 00:00:53,470 --> 00:00:56,480 ‫and I'll call it, My AppSync App, okay? 24 00:00:56,480 --> 00:00:58,220 ‫And each template will deploy an API 25 00:00:58,220 --> 00:00:59,850 ‫and provision DynamoDB tables 26 00:00:59,850 --> 00:01:01,020 ‫and IAM role on your behalf. 27 00:01:01,020 --> 00:01:02,980 ‫So, we'll go ahead and create this. 28 00:01:02,980 --> 00:01:06,220 ‫And as we can see DynamoDB tables are being created 29 00:01:06,220 --> 00:01:08,070 ‫and I just need to wait a little bit. 30 00:01:09,090 --> 00:01:12,600 ‫My API is now created and so, we can first look at 31 00:01:12,600 --> 00:01:15,460 ‫the source of everything in GraphQL which is the schema. 32 00:01:15,460 --> 00:01:17,260 ‫So this is a GraphQL schema 33 00:01:17,260 --> 00:01:18,680 ‫and I'm not going to walk you through it 34 00:01:18,680 --> 00:01:20,100 ‫but this is to find different types. 35 00:01:20,100 --> 00:01:23,080 ‫Such as the comment type, as well as the event type, 36 00:01:23,080 --> 00:01:24,610 ‫the event connection, the comment connection, 37 00:01:24,610 --> 00:01:25,990 ‫the mutation, and so on. 38 00:01:25,990 --> 00:01:28,930 ‫So, these are all needed by GraphQL to function. 39 00:01:28,930 --> 00:01:31,480 ‫So, this is the first thing when we create AppSync we need 40 00:01:31,480 --> 00:01:33,610 ‫to write this entire GraphQL schema which is 41 00:01:33,610 --> 00:01:36,860 ‫about 125 lines long in this example, okay? 42 00:01:36,860 --> 00:01:39,590 ‫Next, we define the data sources and these represents 43 00:01:39,590 --> 00:01:43,290 ‫the two DynamoDB tables that AppSync has created for us. 44 00:01:43,290 --> 00:01:44,850 ‫So, we can click on those 45 00:01:44,850 --> 00:01:47,140 ‫and one of these table will be containing the comments. 46 00:01:47,140 --> 00:01:48,840 ‫One of them will be connecting the events. 47 00:01:48,840 --> 00:01:50,180 ‫So, right now if you go in the tables 48 00:01:50,180 --> 00:01:53,300 ‫and look at the items obviously they're going to be empty 49 00:01:53,300 --> 00:01:54,800 ‫but we'll see how they get filled up 50 00:01:54,800 --> 00:01:57,460 ‫once we get using the API. 51 00:01:57,460 --> 00:01:59,360 ‫Next functions we'll just pass over it. 52 00:01:59,360 --> 00:02:02,350 ‫Queries is, how we can start using our API, 53 00:02:02,350 --> 00:02:03,940 ‫and so this is really cool. 54 00:02:03,940 --> 00:02:07,430 ‫So, we'll use a query, and we have different queries here. 55 00:02:07,430 --> 00:02:11,090 ‫We can do create events or we can do a listEvents, Okay? 56 00:02:11,090 --> 00:02:13,910 ‫So, let's place it on play and say listEvents 57 00:02:13,910 --> 00:02:16,280 ‫and as we can see the data is empty 58 00:02:16,280 --> 00:02:18,610 ‫'cause we don't have any events just yet. 59 00:02:18,610 --> 00:02:22,060 ‫So, let's click again and do a create events, 60 00:02:22,060 --> 00:02:24,040 ‫and my first event has been created, 61 00:02:24,040 --> 00:02:25,870 ‫this is a very, very simple query. 62 00:02:25,870 --> 00:02:28,680 ‫So, you could change the name, the when and the where 63 00:02:28,680 --> 00:02:29,860 ‫and the description here. 64 00:02:29,860 --> 00:02:32,590 ‫So, if I want to say my second events 65 00:02:32,590 --> 00:02:35,720 ‫and then I would run this query against... 66 00:02:35,720 --> 00:02:37,240 ‫I'll say create the events 67 00:02:37,240 --> 00:02:39,480 ‫then this would create my second event, 68 00:02:39,480 --> 00:02:41,930 ‫but now two API queries have been done. 69 00:02:41,930 --> 00:02:44,460 ‫So, if we go into a listEvents, 70 00:02:44,460 --> 00:02:47,540 ‫we can see that we are returning two different events 71 00:02:47,540 --> 00:02:50,540 ‫and if we go into our event table and refresh, 72 00:02:50,540 --> 00:02:52,560 ‫we can see the fact that these events 73 00:02:52,560 --> 00:02:54,540 ‫have been indeed created. 74 00:02:54,540 --> 00:02:55,640 ‫So, this is really cool. 75 00:02:55,640 --> 00:02:59,830 ‫The AppSync API directly inserted data into DynamoDB. 76 00:02:59,830 --> 00:03:02,270 ‫Then you could go ahead and define other types 77 00:03:02,270 --> 00:03:04,060 ‫of mutations for comments and so on, 78 00:03:04,060 --> 00:03:07,510 ‫but for now I'll skip over it they're not easy to add in. 79 00:03:07,510 --> 00:03:10,350 ‫And this is more advanced GraphQL knowledge, 80 00:03:10,350 --> 00:03:12,310 ‫but you get the idea that you could add comments 81 00:03:12,310 --> 00:03:13,440 ‫and they would be linked to events 82 00:03:13,440 --> 00:03:15,480 ‫and they would fill up this DynamoDB table 83 00:03:15,480 --> 00:03:17,540 ‫or the comment table, okay. 84 00:03:17,540 --> 00:03:18,373 ‫Next, we have caching. 85 00:03:18,373 --> 00:03:21,430 ‫So, you have some caching behavior for reducing the number 86 00:03:21,430 --> 00:03:23,410 ‫of queries that you have on your backend. 87 00:03:23,410 --> 00:03:26,110 ‫So, that's a full request caching or per-resolver caching. 88 00:03:26,110 --> 00:03:28,460 ‫Then for your settings you can configure the API. 89 00:03:28,460 --> 00:03:32,750 ‫So, this is my public API that I can share and the API ID 90 00:03:32,750 --> 00:03:36,960 ‫as well as the API key people must use to use our API. 91 00:03:36,960 --> 00:03:38,270 ‫Then we can share the API name 92 00:03:38,270 --> 00:03:40,520 ‫and we can change the default authorization mode. 93 00:03:40,520 --> 00:03:42,260 ‫So, right now we're using API keys 94 00:03:42,260 --> 00:03:44,460 ‫and we can create multiple ones as well, 95 00:03:44,460 --> 00:03:48,610 ‫but it is possible for us to use IAM to have users enrolls 96 00:03:48,610 --> 00:03:51,720 ‫or a cross-account access into our AppSync API, 97 00:03:51,720 --> 00:03:54,760 ‫openID connect or Amazon Cognito User Pool. 98 00:03:54,760 --> 00:03:56,640 ‫If you wanted to connect a user pool 99 00:03:56,640 --> 00:03:59,100 ‫that we have already created, for example this one, 100 00:03:59,100 --> 00:04:01,920 ‫but I won't go into it too much with the ideas that users 101 00:04:01,920 --> 00:04:04,440 ‫or user pool can access your AppSync API. 102 00:04:04,440 --> 00:04:06,760 ‫So, I will not save this obviously. 103 00:04:06,760 --> 00:04:09,560 ‫Then we can add additional authorization providers 104 00:04:09,560 --> 00:04:11,430 ‫which you thought you wanted would allow you again 105 00:04:11,430 --> 00:04:14,240 ‫to use one of these security mechanism, 106 00:04:14,240 --> 00:04:17,200 ‫logging to send it logs into CloudWatch Logs. 107 00:04:17,200 --> 00:04:20,530 ‫Then you have x-ray to have tracing in the extra console 108 00:04:20,530 --> 00:04:22,920 ‫and finally tags and then for the monitoring, 109 00:04:22,920 --> 00:04:24,050 ‫I'm not going to save this. 110 00:04:24,050 --> 00:04:26,050 ‫You could get some metrics information 111 00:04:26,050 --> 00:04:28,590 ‫for your API such as the number of errors, 112 00:04:28,590 --> 00:04:29,770 ‫the total number of request, 113 00:04:29,770 --> 00:04:31,340 ‫there was one request right here 114 00:04:31,340 --> 00:04:33,750 ‫and the latency you get for your API. 115 00:04:33,750 --> 00:04:35,150 ‫So, all are very, very easy 116 00:04:35,150 --> 00:04:37,670 ‫and that's the basics of AppSync. 117 00:04:37,670 --> 00:04:39,070 ‫So, that's it. 118 00:04:39,070 --> 00:04:40,480 ‫Don't worry too much about the details. 119 00:04:40,480 --> 00:04:42,610 ‫This is just a very, very small 120 00:04:42,610 --> 00:04:44,740 ‫maybe one question in your exam, 121 00:04:44,740 --> 00:04:47,410 ‫and you do know that AppSync is GraphQL, 122 00:04:47,410 --> 00:04:49,910 ‫could be WebSockets and could be used 123 00:04:49,910 --> 00:04:53,310 ‫to do mobile data offline synchronization 124 00:04:53,310 --> 00:04:56,590 ‫and then finally to just delete this, you click on this API 125 00:04:56,590 --> 00:04:57,760 ‫and click on delete. 126 00:04:57,760 --> 00:05:02,010 ‫So, you have to enter the name of the app to delete it. 127 00:05:02,010 --> 00:05:03,690 ‫So, this is how I'm going to do it, 128 00:05:03,690 --> 00:05:06,020 ‫but funnily enough if you delete this API, 129 00:05:06,020 --> 00:05:08,270 ‫it doesn't delete the DynamoDB tables. 130 00:05:08,270 --> 00:05:10,700 ‫So if I refresh this page I'll show you why. 131 00:05:10,700 --> 00:05:12,790 ‫So, the DynamoDB tables are not deleted. 132 00:05:12,790 --> 00:05:15,320 ‫So, if you don't want to spend some money 133 00:05:15,320 --> 00:05:19,070 ‫then you need to delete manually these two DynamoDB tables. 134 00:05:19,070 --> 00:05:21,220 ‫This is a bit annoying, but we have to do it. 135 00:05:21,220 --> 00:05:22,710 ‫So, we'll delete these two, 136 00:05:22,710 --> 00:05:24,190 ‫and this is a cleanup for this hands on. 137 00:05:24,190 --> 00:05:25,023 ‫So that's it. 138 00:05:25,023 --> 00:05:27,840 ‫I hope you liked it and I will see you in the next lecture.