Skip to content

Instantly share code, notes, and snippets.

View zainafzal88's full-sized avatar

Zain Afzal zainafzal88

View GitHub Profile
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
"Resources": {
"AspNetCoreFunction": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "CommentsAPI::CommentsAPI.LambdaEntryPoint::FunctionHandlerAsync",
"Runtime": "dotnetcore3.1",
private const string TableName = "comments";
private readonly IAmazonDynamoDB _amazonDynamoDb;
public CommentsController(IAmazonDynamoDB amazonDynammoDb)
_amazonDynamoDb = amazonDynammoDb;
public async Task<ScanResponse> GetComments()
<div class="comments-view">
<h4>Please Share Thoughts</h4>
<input id="name" type="name" class="form-control" placeholder="Enter your email">
<textarea id="comment" class="form-control" placeholder="Share thoughts here"></textarea>
<button id="submit" class="btn btn-primary" >Comment</button>
<div id="all-comments" class="show-comments"></div>
let allComments = document.getElementById("all-comments");
let $name = $("#name");
let $comment = $("#comment");
$("#submit").on('click', function(){
//validation to prevent html tags being inputted input box
public class Comments
public string Username { get; set; }
public string Comment { get; set; }
public string PostId { get; set; }
public async Task Post([FromBody] Comments comment)
Guid uuid = Guid.NewGuid();
var item = new Dictionary<string, AttributeValue>()
{"id", new AttributeValue{S = uuid.ToString()}},
{"username", new AttributeValue{S = comment.Username}},
{"comment", new AttributeValue{S = comment.Comment}},
{"postId", new AttributeValue{S = comment.PostId}},
public async Task Delete(string id)
var request = new DeleteItemRequest
TableName = TableName,
Key = new Dictionary<string, AttributeValue>()
{"id", new AttributeValue{S = id}}