Skip to content

Instantly share code, notes, and snippets.

View jiimaho's full-sized avatar
🎯
Focusing

Jim Aho jiimaho

🎯
Focusing
View GitHub Profile
@jiimaho
jiimaho / Exception.cs
Created June 21, 2021 19:14
Better logging in catch
try
{
// network call
}
catch(Exception e)
{
_logger.Warning(e, "Network call failed");
}
@jiimaho
jiimaho / Exception.cs
Created June 21, 2021 19:17
Good usage of fatal logging
try
{
// notify customer about rejected card purchase
}
catch(Exception e)
{
_logger.Fatal(e, "Failed to notify customer about rejected card purchase. Please ask Customer Care Center to call the customer and tell him/her about this to avoid degradation of reputation");
}
@jiimaho
jiimaho / Models.cs
Last active August 14, 2021 09:06
Models
public class CustomerIntegrationModel
{
public string CustomerId { get; set; }
public string Name { get; set; }
}
public class CustomerRequestModel
{
public string CustomerId { get; set; }
public string Name { get; set; }
{
"attribute1": {
"DataType": "String",
"StringValue": "value1"
}
}
{
"Source": "From AWAS CLI",
"EntityId": "e165a1df-f792-4043-a601-929c1576ee1d"
}
public class CustomerModel
{
public string CustomerId { get; set; }
public string Name { get; set; }
}
public async Task FunctionHandler(SQSEvent evnt, ILambdaContext context)
{
// Calling CreateScope() here is required to resolve scoped services correctly
using var scope = ServiceProvider.CreateScope();
await scope.ServiceProvider.GetService<App>().Run(evnt);
}
@jiimaho
jiimaho / Program.cs
Last active November 14, 2021 10:20
SimpleDynamoDbQuery - whole
// See https://aka.ms/new-console-template for more information
using System;
using System.Collections.Generic;
using System.Linq;
using Amazon;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using IAmazonDynamoDB client = new AmazonDynamoDBClient(RegionEndpoint.EUNorth1);
@jiimaho
jiimaho / Program.cs
Created November 13, 2021 18:05
SimpleDynamoDbQuery - connection
using IAmazonDynamoDB client = new AmazonDynamoDBClient(RegionEndpoint.EUNorth1);
@jiimaho
jiimaho / Program.cs
Last active November 14, 2021 10:28
SimpleDynamoDbQuery - query
var query = new QueryRequest
{
TableName = "customertestjim",
KeyConditionExpression = "CustomerId = :Id",
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{
{ ":Id", new AttributeValue { S = "12345" }}
}
};