Library

Video Player is loading.
 
Current Time 0:00
Duration 18:31
Loaded: 0.00%
 
In this tutorial we're gonna learn how to connect an AWS lambda function to
x1.00


Back

Games & Quizzes

Training Mode - Typing
Fill the gaps to the Lyric - Best method
Training Mode - Picking
Pick the correct word to fill in the gap
Fill In The Blank
Find the missing words in a sentence Requires 5 vocabulary annotations
Vocabulary Match
Match the words to the definitions Requires 10 vocabulary annotations

You may need to watch a part of the video to unlock quizzes

Don't forget to Sign In to save your points

Challenge Accomplished

PERFECT HITS +NaN
HITS +NaN
LONGEST STREAK +NaN
TOTAL +
- //

We couldn't find definitions for the word you were looking for.
Or maybe the current language is not supported

  • 00:00

    In this tutorial, we're gonna learn how to connect an AWS lambda function to

  • 00:04

    DynamoDB so the first thing we're going to do is create a table in DynamoDB. So,

  • 00:11

    let's first go to our DynamoDB service and create a new table. So, this is the

  • 00:18

    DynamoDB AWS console you can view your tables here. I have a few tables already.

  • 00:24

    This is the dashboard and there's a button on the dashboard to create a new

  • 00:29

    table. So create a table and name your table. In this example we're going to

  • 00:35

    have our table called message and we need to choose the primary key for our

  • 00:44

    message table, in this case, I'm going to have our primary key be a GUID that

  • 00:50

    comes from a request ID. So, we're going to call this messageId and a GUID will

  • 00:56

    be a string. Keep everything else as default and you create.

  • 01:02

    So here is your new message table the table name is message we have our

  • 01:08

    primary key as message ID everything here is our table setup with all its

  • 01:14

    details and this is actually the Amazon resource name if we were going to

  • 01:19

    restrict our lambda functions to write to a specific table only we would need

  • 01:24

    to have this resource name for our example we're going to have it be able

  • 01:29

    to write to all tables so now let's set up our lambda function going back to our

  • 01:34

    AWS management console I'm going to go to our lambda

  • 01:41

    so I have some functions already but we're going to make a new function and

  • 01:46

    this is going to write a message to our message table in the creative function

  • 01:51

    and it's going to be from scratch and the function name is going to be right

  • 01:59

    message and what this function will do is create a new message in our message

  • 02:07

    table on DynamoDB our runtime info will be no js' that we're going to click

  • 02:12

    create function

  • 02:17

    so now we have successfully created our new function it's called bright message

  • 02:23

    decisions the sample nodejs code that Amazon already fills in for us we're

  • 02:30

    going to change this so that it can write to the dynamodb and we're going to

  • 02:36

    just change it within this editor so the first thing we're going to do is import

  • 02:41

    in the code that we need to so that we can use the Amazon SDK so we're gonna

  • 02:47

    make a Const call this AWS and we're going to tell it to require the AWS SDK

  • 02:59

    then we need to connect to our dynamo DB so you're gonna declare Const this will

  • 03:08

    be called DD be our dynamo database equals new and then we're going to use

  • 03:18

    our ABA AWS that we create it so new AWS dot 0 to be document client and then

  • 03:32

    we specify the region our DynamoDB existing so in this case our region is a

  • 03:39

    USB stash one we created it in North Virginia that is Amazon's

  • 03:45

    us - East that's - one we're gonna write in curly braket region us - East - one

  • 04:00

    semicolon and a line break but now we need to modify our handler to write to

  • 04:06

    dynamo dB so we have our handler it's going to

  • 04:11

    have an async event and we're going to also add in a context and a callback

  • 04:24

    context is the data that's being sent in to us and callback is what's actually

  • 04:28

    going to be returned we do not need this code so we're gonna write as our message

  • 04:35

    ID a gooood and what I'm going to use right now is the AWS request ID that is

  • 04:41

    coming in from context in a production environment you wouldn't use this do

  • 04:46

    this you would normally generate a brand new good but for the sake of this

  • 04:51

    example we're going to just stick with an easier example so we're gonna just

  • 04:55

    use that request ID so I'm going to declare a constant request ID equals

  • 05:02

    context dot AWS request ID I'm now going to make a new function within JavaScript

  • 05:16

    they work with promises and observables this function is going to return a

  • 05:20

    promise so I'm gonna make a new function and I'm gonna call this create message

  • 05:28

    and it will take in the request ID what we're gonna do is write to the DynamoDB

  • 05:40

    for our table name message so we're going to set up some parameters that

  • 05:46

    we're going to be passing over so I like to make Const params equals and we set

  • 05:53

    up our parameters of what we're writing so the first thing that's expected is

  • 05:57

    the table name so they say table name and our table name was message comma

  • 06:09

    then the item this is what we are writing to the table so the one thing

  • 06:16

    that is required is the message ID so message ID and that will be the request

  • 06:28

    ID we also want to store a message so let's

  • 06:34

    say a lowercase message right hello from lambda now this would be where you would

  • 06:46

    use your contacts to get a message that a user sent over but for this purposes

  • 06:52

    of this tutorial we're gonna stick to it being simple and just hard-coded in this

  • 06:58

    sets up the parameters now we need to write it to the database so in order to

  • 07:05

    write to the database we will go ddb dot put we pass in the parameters and we

  • 07:14

    need to return something so in this case I want to return a promise so I'm going

  • 07:19

    to write return a DB put brands dot promise so this is the function that

  • 07:32

    we'll set up to write to our database put is going to place those items into

  • 07:39

    our database message doesn't exist but DynamoDB is a no sequel database this

  • 07:46

    will be added when we write it to the database so we need to call create

  • 07:51

    message so we write a wait create message we pass in our request ID and

  • 08:02

    then we use then

  • 08:08

    we're going to return something so if it's not an error we are going to use

  • 08:15

    our callback to return a respond or going to say callback it's not an air so

  • 08:22

    we're going to put a null and the body will be our status code so we inserted

  • 08:30

    something into the database so we're going to return a status code of 201

  • 08:33

    so status code 201 we're not going to have a body so it's just going to be an

  • 08:43

    empty body so body empty and we want to enable our cross origin is course so

  • 08:52

    we're going to do headers and then our access control Wow it'll be so this is

  • 09:12

    our callback this will be the response that comes back what if there's an error

  • 09:16

    well let's handle that as well so if there's an error we want to catch the

  • 09:22

    air so we'll catch specifically a parameter called air and we are going to

  • 09:28

    write to the console the air so we're going to write console dot air and we'll

  • 09:37

    write the error message so this is all the code we need to write to the

  • 09:43

    database but we are not done yet if we try to test this code right now we're

  • 09:48

    going to get rejected when writing to DynamoDB if I make a test we can just

  • 09:56

    use this sample one test we don't need any ending in our body so I'm going to

  • 10:01

    create this so make sure we save and then let's test

  • 10:08

    and we get an air back saying our access was do not denied for our role right

  • 10:15

    message so let's edit our right message role so that we can write to the

  • 10:21

    dynamodb we're gonna scroll up go to permissions we're going to click our

  • 10:29

    right message role and this will open up our right message role and with that we

  • 10:36

    have a policy this is the AWS basic execution rules and what we want to do

  • 10:40

    is add on to this so we're going to edit this policy or click Edit policy add

  • 10:47

    additional permissions we're going to choose a service we're going to choose

  • 10:52

    dynamo DB and in this example we're going to give permission to write to all

  • 10:58

    tables on our dynamo DB so all dynamo DB accesses we want it to read write scan

  • 11:05

    and with that we need to give it permission to all resources now if we

  • 11:12

    want it to restrict it we can restrict it down to a specific table and that's

  • 11:18

    when if we go back to our dynamo DB you would need your information of your a RN

  • 11:25

    or amazon resource name and that's where you can restrict it to only being able

  • 11:29

    to query one table going back to our permissions here I'm going to say all

  • 11:35

    resources though this is set up completely and

  • 11:40

    we're gonna say review policy there's our DynamoDB with full access to

  • 11:47

    all resources we're gonna click Save Changes it has been updated now with

  • 11:54

    dynamo DB so let's go back to our right message lambda function and let's test

  • 12:01

    it again and see if it succeeds so we're gonna click test and we get back the

  • 12:07

    status code is 201 and it's all successful let's go over to our dynamo

  • 12:13

    DB go to items tab we can refresh this view and there is our message hello from

  • 12:22

    lamda so now we've learned how to write to a dynamo dB let's learn how to read

  • 12:28

    from the dynamo DB I'm going back to lamda and I'm going to make a new lambda

  • 12:34

    function and this is going to be called read message to function read message we

  • 12:44

    create our function

  • 12:48

    now the setup for reading from our data from our database is going to be very

  • 12:54

    similar to writing to our database - how we query the information so let's copy

  • 13:00

    from the other area where we declared our AWS and ddb I'm going to add that to

  • 13:06

    the top of our index j s and now we need to modify our exports so exports top

  • 13:14

    handler we're going to take the exact same async signature that we used

  • 13:19

    earlier so that's events context and callback now what we need to do is

  • 13:28

    create a method that scans our database in this case we are going to call our

  • 13:35

    dynamo DB and just get back ten of the messages in the database if there is ten

  • 13:42

    we're gonna make a method I'm gonna remove this code we're gonna write a

  • 13:46

    wait and this will be called read message it will take no parameters and

  • 13:55

    we're gonna have our it's gonna be a promise so we'll have our thing that

  • 14:01

    will return back some form of data which will be what we're querying otherwise it

  • 14:06

    will have an air so then whenever we're going to do otherwise we catch our air

  • 14:13

    and we'll do the same thing we did in the last example so we'll walk the air

  • 14:20

    console dot and so let's define the function read message function read

  • 14:34

    message no parameters and our parameters are going to be similar to our create

  • 14:42

    message so I'm actually going to use the exact same parameters but there's Kant's

  • 14:48

    pram I'm having my table name message I'm not inserting any items we're going

  • 14:54

    to be using a limit so limit

  • 14:59

    10 now I'm going to call dynamodb and scan the database so this is going to

  • 15:06

    return d DB dot scan passing in our params dot promise so this is going to

  • 15:22

    return back data this time so this will have a list of items that we are going

  • 15:28

    to out print but we're going to say data dot items these are the items being

  • 15:35

    returned for each we make a function

  • 15:42

    item it's the code block will do console dot

  • 15:48

    blog and we'll say item dot message this would be for the one item that we have

  • 15:58

    in the table it would say hello from lambda so let's save this if we run this

  • 16:04

    code right now the lambda function does not have the correct permissions the

  • 16:09

    role that the lambda functions executing on so let's change our role so let's

  • 16:13

    scroll up let's go to our permissions and we can either update this read

  • 16:22

    message to have permissions to read from the DynamoDB or we can edit our

  • 16:28

    execution role and choose our write message will so let's choose right

  • 16:33

    message and we'll hit save and now our read message and right message are

  • 16:39

    executing under the same role so if we test our function to get our results

  • 16:46

    back we're not returning anything with our call back but we log hello from

  • 16:51

    lambda so now you've learned how to read from dynamodb so you might be saying

  • 16:57

    wait a minute I don't want to just log it to the console

  • 17:00

    I want the response to come back through our API

  • 17:05

    well let's modify our callbacks so you do call back

  • 17:11

    this is when it is successful so how long no and then defining our body so

  • 17:18

    this case our status code should be 200 it's successful but we didn't insert

  • 17:23

    anything into the database tool same status code 200 the body is going to be

  • 17:32

    the items in our database that we are returning back so we'll say body data

  • 17:41

    items because that's what we're doing here we're doing our data items for each

  • 17:46

    and reloading them now our data items is what's going to be our body and we add

  • 17:52

    our header so headers I'm just gonna copy it from our other lambda function

  • 18:00

    headers there's our access control origins for all the click safe and let's

  • 18:08

    test this you get our test and now we have our response with each message in

  • 18:16

    there if there's multiple message this will be curly brackets comma and then

  • 18:20

    the next message so in congratulations you have learned

  • 18:23

    how to read and write to dynamo DB using AWS lambda functions

All

The example sentences of QUERYING in videos (3 in total of 3)

will modal return verb, base form back adverb some determiner form noun, singular or mass of preposition or subordinating conjunction data noun, plural which wh-determiner will modal be verb, base form what wh-pronoun we personal pronoun 're verb, non-3rd person singular present querying verb, gerund or present participle otherwise adverb it personal pronoun
now adverb the determiner user noun, singular or mass agent noun, singular or mass is verb, 3rd person singular present querying verb, gerund or present participle on preposition or subordinating conjunction my possessive pronoun behalf noun, singular or mass and coordinating conjunction should modal know verb, base form what wh-pronoun i personal pronoun want verb, non-3rd person singular present to to see verb, base form .
now adverb that preposition or subordinating conjunction you personal pronoun 've verb, non-3rd person singular present ingested verb, past participle your possessive pronoun data noun, plural to to s proper noun, singular 3 cardinal number , you personal pronoun 'll modal probably adverb like verb, non-3rd person singular present to to start verb, base form querying verb, gerund or present participle the determiner data noun, plural .

Definition and meaning of QUERYING

What does "querying mean?"

/ˈkwirē/

verb
To ask a question, e.g. because you have doubts.

What are synonyms of "querying"?
Some common synonyms of "querying" are:
  • ask,
  • inquire,
  • question,
  • quiz,

You can find detailed definitions of them on this page.