John Smith
John Smith

Reputation: 483

How to insert items into AWS dynamoDb from external website

I would like an external website (under my control) to insert items into my AWS dynamoDb table.

I have considered using AWS API gateway with AWS Lambda, but I'm not sure how to achieve authentication between external server and my AWS hosted application.

Does this sound like a good approach? Do you have any other approaches?

Thank you!

Upvotes: 0

Views: 361

Answers (2)

D. Richard
D. Richard

Reputation: 474

You could also use this: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Js.03.html Add a custom header like this:

X-API-KEY: PutRandomStringHere 

to your request in order to protect your External Server from unknown traffic. Your External Server in this case is API Gateway and Lambda. Then, your External Server needs to authenticate to AWS with an AccessKeyId and SecretAccessKey combination. Seeing the flow?

Upvotes: 0

Jaime S
Jaime S

Reputation: 1698

Your approach sounds perfectly fine for me. You can use API Gateway with Lambda proxy to insert records in DynamoDB. I think that it's a very common architecture. You can see an example here (https://www.youtube.com/watch?v=rRvy5Fbei1s) whenever I look for ideas about SW architectures using AWS I use: https://aws.amazon.com/this-is-my-architecture

Regarding to the authentication that also depends of your external caller, for example if you have a JWT or JWK you can pass it to your gateway in a header and validate it using the lambda:

const AWS = require('aws-sdk');
const jwt = require('jsonwebtoken');

exports.handler = async (event) => {

    let token = jwt.decode(event.headers.Authorization);
    console.log("Token information: " + JSON.stringify(token));

    // You can also validate the JWT signature,
    // expiration time, sub etc..
    // and then perform the dynamoDB inserts...
};

hope this helps

Upvotes: 2

Related Questions