Going NoSQL with ApsaraDB for MongoDb Or Table Store

Building a serverless application on AWS — Part 2: Create a DynamoDB table and store data

In the first article in this series I gave you a brief example how to build a simple API and ship it to AWS. Now it's time to put more logic into the API.But… so far I did not explain anything what you want to build in the end. Let's change that now; here are the requirements:A user is able to upload an image. For each uploaded image three different thumbnails should be created (small, medium, large). Before doing that the uploaded image needs to be validated. Only image/jpg, image/jpeg and image/png are allowed. At any given time the user is able to check the current status of the image processing. An image can have one of the following status: waiting_for_upload, waiting_for_thumbnails, published and in case of an validation error invalid_content_type. PrerequisitesBefore you start the implementation let me give you an introduction into AWS DynamoDB first.Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability.One of the most important part of using a NoSQL database (AWS DynamoDB) begins before you ever put data into it; designing the table and the corresponding primary keys. AWS DynamoDB supports two types of primary keys to choose from, a Hash Key and a Hash and Range Key.A Hash Key consists of a single attribute that uniquely identifies an itemA Hash and Range Key consists of two attributes that together, uniquely identify an itemTo see both types of primary keys in action I will provide you an example of each with the writing and reading operation together with the AWS CloudFormation AWS::DynamoDB::Table resource.Example: "Hash Key" based primary key1. Write operation2. Read operation3. AWS CloudFormation resourceExample: "Hash and Range Key" based primary key1. Write operationThe difference is that you are forced to add the required "Range Key" (createdAt) in the put operation.2. Read operationThe difference is to use the query operation instead of put.3. AWS CloudFormation resourceThe difference is to define createdAt as RANGE key (Line 7-8 12-13). Let's get back to work now…So which type of primary key should you choose? Well, it depends. Do you want to store multiple items for the same ID (hash key) or is it enough to have only one item per ID (hash key)?With the requirements in mind I assume you already designed a simple entity like this:Referring to that entity the "Hash Key" based primary key is enough. The only thing we want to do is to update the status of our entity along the different processes. Therefore let's create the DynamoDB table right away. You can find the matching AWS CloudFormation resource in , Line 6-17.As you also want to store the uploaded images somewhere; I highly recommend to use AWS S3 for that. The AWS CloudFormation resource for that can be found in , Line 1-4.As soon as you created these two resources you can start to change the logic of the API.Disclaimer; AWS API Gateway has a Payload size limit of 10mb (which cannot be increased), because of that we need to find a workaround in case our user wants to upload an image which has more than 10mb in size. For that we are using an API offered by AWS S3 to generate a pre-signed URL. A "pre-signed URL" is a URL which grants the user temporary access to AWS S3, but only to one specific object in it. The pre-signed URL expires after a given time (default: 5 minutes). To be concrete: The user is doing a GET request against your API and as a response the user get an uploadUrl. In the second step the user has to do a PUT request against the uploadUrl with the image binary as payload and application/x-www-form-urlencoded as Content-Type.Let's check how this is implemented:persist initial image data with status waiting_for_upload (, Line 13-20)generate uploadUrl with help of the AWS S3 SDK (, Line 22-29)returnuploadUrl (, Line 31-35)Two last steps are missingFirst: In our updated API we are referencing two new environment variables BUCKET_NAME and IMAGE_TABLE. So we need to pass them to our application as well. To achieve that you need to change the ApiLambda resource and add Environment.Variables property. Check , Line 24-27.Second: Two new AWS services are called in your application; AWS. S3() and AWS. DynamoDB. DocumentClient(). With the existing configuration your application will fail with a PermissionDenied error. To tackle that you need to add two more policies to ApiLambdaExecutionRole resource. Check , Line 13-14.Hint: As soon as you are using a new AWS service (e. g. DynamoDb, S3, etc. ) in your application it's most likely that you have to add a new policy to your ExecutionRole in order to grant access to these services. Following this small hint saves you a lot of (debugging) time. Trust me.At any given time the user is able to check the current status of the image processing. Following this quote out of the requirements you need to setup an API route to receive the latest status of the image processing. It's easy as its sounds.Get the latest data out of AWS DynamoDB (, Line 8-20) and return it (, Line 22-27).In my next article I will explain you how to validate uploaded images and how to create thumbnails from them. That's it. Feel free to check the GitHub repository and see how it evolves through this article series. Hope I helped you a little bit in the big -serverless- world. Stay tuned!-Maik

get in touch with us
empfohlene Artikel
Blog
Back to School Help!Read Details! Get 10Points For1 with Best Outfit!?
go to www.polyvore.com and type in first ay of school and people make collages of what to wear and on the side it tell you wear you can buy it i love that website go check it out• Related QuestionsHow do you like my first chapter?It sounds just like Twilight only difference is the chick is the vamp. I bet next chapter will feature a boy who has an 'aura' that makes her want to suck his blood or something equally ridiculous.Your originality staggers me.------Is this an incredibly stupid idea?technicality you shouldn't get in trouble for that... but i have gotten in trouble for similar things when i was in school... they called it a distraction to other students (i was doing the goth thing before it was popular).------What to wear now in Miami?TRAVEL LIGHT AND ALWAYS BRING A CHANGE OF CLOTHES FOR A NIGHT ON THE TOWN!! tHE BEACH IS THE NECESSARY BIKINI REGARDLESS, AND THE NIGHT LIFE IS NOT MUCH MORE IF YOUR LOOKIN FOR A GREAT TIME...........iT IS MIAMI!!!!!------Should I wear a dress or a skirt on Valentine's Day?It depends upon the weather for me really. Within the fall I like to wear longer skirts and in the wintertime I wear longer ones with my boots, however in the spring and summer I prefer to wear short summer dresses------am looking for a wedding gown that i saw in a magazine years ago, fell in love with it. now cant find it help?Have you gone to a bridal shop yet? There may be some that have an archive of sorts of wedding gowns (photos, magazines, etc) that you may be able to find something close if not 'the one'.Good luck & Congrats------Can anyone read about these dreams for me please?Well, i think you like this guy. But you may be scared and unsure of what your friends think of it. try talking to your friends :)help me? thanks ------how do i look cute with my dress code?oh gosh...wow, that must be tough but one word ACCESSORIES! i now leave you to think...try: hope you find something you like :)------Ladies what is a good outfit for fall weather?girl jeans--ripped.((makes guys look so effin sexy))brown and red colors.((to make you blend in with the season))and some nice high heels that are so god damm gourgous it makes girls jeloushahahhope this helpssexy bioch------How is my intro for my story?i don't think you should say "all the more scary looking" in paragraph # 2. and in paragraph # 3 maybe u should say the doll looked most appauling afyter seeing the red yarn stiched over the mouth. Other than that AWESOME!------How would someone with this personality look/dress like?So if she is wealthy and artistic, probably like beige trousers with a navy blue jacket and white top. OR mayeb this outfit jpg.------This is the first half of chapter 1 in my book I'm writing. Can anyone read it and tell me how it is?omfg that is such a good story it makes me think of the twilight saga i love how you give so many details and describe his face i love the names and you need to keep on writing keep me updated------What shall i do about my daughter starting middle school???!?Woah, when I was that age I went to bed at 9:00 and read for an hour. I would say 8:30 - 10:00. Take her on a shopping spree at Justice. They have 40% off sales and cute clothes too. No more movies and chocolate------does anybody want to make me an outfit?Age: 15 Gender: woman form: in maximum circumstances Skater with incredibly Like, Prep colors: Any shade of green, Black, pink, Blue, pink clothing: T-Shirts, Hoodies, skinny denims shops: PacSun, Delias, heat concern count number, Abercrombie shoes: communicate, autos upload-ons: Necklaces, rings------Back to school clothes shopping list!!?I like girls in jeans. It makes them look more home town like and it doesn't look like they try too much but if you are looking to get this men attention, this might not be what you would like------beauty tips for young teen plz?were just the same but im tall not short lolthis is what goes on menavy blue, tan , dark greensskinny jeansflats or kitten heelst-shirts on long vestslongs coats that elongats your figuehope this helps------shorts and a band-aid, or should i cover it up.?Shorts Shorts Shorts.Oh god Please Do Not Wear A Long Sleeve ShirtUnder A Spaghetti Strap Dress.Just Wear Shorts and Everything Will Be Fine,I Mean If You Have Your Ankle Brace,Then Why Does A Band Aid Matter.------Can i wear a long sleeves dress to prom?Hello:Yeah go for it. but if you'd like to be in style try making one out of clean unused plastic garbage/trash/bin bags. That material is in style these days. I hope I helped, if not I'm sorry.------Can i just wear a t-shirt and pants for ice skating and not a long sleeve or with jacket?well it depends if your a good skater or not ....if its your first time ... wear jeans ... it don't hurt as much when you fall over ... and also wear a jacketthe temperature is normally 0-3 degrees in indoor rinks------Winter mommies...what type of outfit?i live in michigan. so it may be a little different. plus my son was born in march. but he went home in a university of michigan sleeper. we had a huge snow storm the day my son was born too------fashion/dress for teen girls in boston?Boston gets very cold in the fall/winter so make sure you pack a lot of warm clothes such as jackets, sweatshirts/pants, jeans, long sleeves, etc...In September, you could probably wear shorts if it's early in the month------Cute Ways To Dress For School?This Site Might Help You.RE:Cute Ways To Dress For School?I really like blue jeans and layering shirts , what are some things i can use as comfy assecories and some cute casual things to do with my hair THANKS------At a traditional Catholic wedding w/o communion at 7pm, do I have to wear a long dress??I like girls in jeans. It makes them look more home town like and it generally does not look like they try too hard but if you are looking to get this men attention, this might not be what you want------I think one of my students is being neglected/abused?well...don't you have an obligation to report anything out of the ordinary?? I would talk to the guidance counselor at your school and see what the next approach would be...they are better equipped for situations like yours. good luck------I'm fashionably challenged please help?well, 10 things that a teenage girl must have in her wardrobe are1) a little black dress2) a trench coat3) heels4) neutral coloured flats5) neutral coloured handbag6) a cardigan7) a blazer8) a day dress9) good pair of jeans10) an all occasions top------What is your school's dress code?bottoms, below fingertips3finger sleeveswe are allowed to wear any type of shoes, including flipflopspajamas are not a problem, (besides by style)those saggy type hats are acceptable, but not like sports capsheadbands everyone wears themhoodsno------Which of these dresses do you like the most?hey, i like the first one which is pink. It will really suit your age. If you changed the color to Black would also be nice. I have noticed that all of the dresses are short. Yet they are really pretty!------Anyone else have a daughter/s like this?Well u cant get her all dresses because school starts in the fall which means winter is right around the corner and you just said that she'll wear pants wen its cold so yes get her some pants as well :)------Why do females athletes wear tiny clothing and males dont?Sad to say but I think they want to make a fashion statement. Who knows maybe it's an endorsement for the clothing and so they get money for it. You are right others do just fine and even win some!.------Do women care how a man dresses or is that only shallow immature girls who do?Clothes do matter to me, because they tell you a lot about someone.I just know that I'm going to probably get along better with a guy who has really casual style and dresses for comfort and function rather than fashion.------What is the Disneyland dress code you must have to work there?I really like little skirts and the real way i fix it being brief is leggings and coloured tights. Not the methods with holes however the ones that virtually look like leggings but are obviously tights as a result of material------15 year old girl always comes to class with injuries?Yes, because if there is an abusive parent, someone needs to intervene. Same case if this student's injuries were self-inflicted, which would indicate depression.Unless she secretly fights criminals in her free time and picked up injuries from there.------what can i wear over or under this dress to be warm at a New York evening Wedding? Shoes - Or if you don't like them look at the rest of the shoes on the site.------What kind of hairstyle will look nice with this dress?Angel,it incredibly is a quite gown,yet as a guy,i think of somewhat like the type interior the image,it exhibits the gown and your self greater powerful,in case you spot my factor,so have an astounding time to------Why am I the only one to dress for the cold appropriately at school?I asked myself this same question when I moved to CT. In the winter it gets cold. However, I see many people in shorts and a zipped or pullover sweater. No lie, I even seen this one girl in flip flops.------Anyone with a sense of fashion... please help?I have a good look Somethign like that.------Wearing A Cherry Red Dress To A Wedding?I like females in jeans. It makes them look more city like and it generally does not look like they are trying too hard but if you're trying to get this guys attention, this may well not be what you would like------What would you call my style???? :)?It's really cute and laid back. I think it's more of a girly style with a slight edge.Also, if you want to add details, you can. It's under the edit link on your question or something.------I need a new wardrobe for fall I'm 23. I want advice on what basic essentials I should get to mix and makeGet classic clothes that don't go out of style, and accessorize. The accessories can change with time and you can wear the same clothes as a base. You keep up with fashion trends this way, and save money too.------Where can I find a sweater dress for a reasonable price?urban planet, urban outfitters, costa blanca....those are the only ones i can think of, and i dont know if you have one near you or not.also, a good suggestion, thrift stores! cheap, and you never know what youll find:)------Fall wardrobe for school aged children?my daughter wears uniforms, so i replace them as needed. i never went heavy into shopping as they had plenty of clothes from the summer to last a few months into the school year. i replaced clothes as need then, too------I'm 15 and going to a Georgia wedding in November. What should I wear?!?This is a pretty dress, it's short so not too dressy, but still elegant. Forever 21 has lots of cute dresses...and cheap! ------Why do people think that western riders are pur redneck hillbillies that don't care about their horse?Same reason people think english riders are stuck up snobs that wear their jods so tight so the sticks don't fall out of their butts. Ignorance and bigotry.There are amazing riders of both disciplines. And total jerks in both.------Survey: What is your style? (GIRLS)?1. jeggins and pumps and top and cardigan2. demin skirt and tank top (if its actually hot)3. jeans/jeggins or skirt with tights, uggs and hoodie4. jeggins and hoodie, pumps or uggs5. hollister, river island, primark..random ones6. pink7. down and straightened------What do you think? I'll answer yours if you answer mine. A little bit long, but please help. I'm confused!?It does sound like he likes you, but he may be shy about it or unsure of what to do. You may need to make the first move if you really want something to happen between the two of you------for grae 8 grad i have a dress its like not straps or tube tops its full length and full sleeves but all the?Psh no,it sounds like there trying to be too grown up and to slut-like.As long as your dress is pretty and is not covering your body from the top pf your head to the floor, u should be fine.------Have no idea what to wear on first day?!? would work well :) I suggest lose fitting but not baggy shirt with shorts or boyfriend jeans :P------what is this fall's fashion?cuffed high boots, skinny jeans, and stripped long sleeve sweaters. Thick belts around the waist with a long white shirt and black leggings, kimono styke dresses and peep toe shoes... Try looking at this months issues of Lucky fashion magazine and glamour.
Design Scheme of Multi-channel Voltage Measurement Based on Stm32
How Does Temperature Affect the Speed of Sound?
What Is WiFi? Just Tell Me What It Is, and What It's Used For.?
Which Is Better, WiFi Or ZigBee Wireless Technology
Smart Home Promotes Building Intercom into Thousands of Households, with Large Stock and Incremental
Upgrading of Set Top Box
Buying Manchester United Tickets Online with a One United Membership?
The Benefits of Using the Right Fence Post Lights
Gentlemen, Meet My New Friend Mr Porter
related searches
Back to School Help!Read Details! Get 10Points For1 with Best Outfit!?
Design Scheme of Multi-channel Voltage Measurement Based on Stm32
How Does Temperature Affect the Speed of Sound?
What Is WiFi? Just Tell Me What It Is, and What It's Used For.?
Which Is Better, WiFi Or ZigBee Wireless Technology
Smart Home Promotes Building Intercom into Thousands of Households, with Large Stock and Incremental
Upgrading of Set Top Box
Buying Manchester United Tickets Online with a One United Membership?
The Benefits of Using the Right Fence Post Lights

KingBird Home Furniture