Skip to content

Instantly share code, notes, and snippets.

@Blind-Striker Blind-Striker/Handler.cs
Last active Aug 13, 2019

Embed
What would you like to do?
Sample for LocalStack article
public async Task<APIGatewayProxyResponse> CreateProfileAsync(APIGatewayProxyRequest request, ILambdaContext context)
{
WriteVariables(context);
string requestBody = request.Body;
context.Logger.LogLine($"Request Body\n {requestBody}");
AddProfileModel addProfileModel = JsonConvert.DeserializeObject<AddProfileModel>(requestBody);
context.Logger.LogLine($"Decoding Base64 image");
var bytes = Convert.FromBase64String(addProfileModel.ProfilePicBase64);
var fileTransferUtility = new TransferUtility(_awsS3Client);
using (var ms = new MemoryStream(bytes))
{
context.Logger.LogLine($"Uploading {addProfileModel.ProfilePicName} to {BucketName}");
await fileTransferUtility.UploadAsync(ms, BucketName, addProfileModel.ProfilePicName);
}
context.Logger.LogLine($"Adding profile to DynamoDb");
await _awsDynamoDbClient.PutItemAsync(TableName, new Dictionary<string, AttributeValue>()
{
{nameof(AddProfileModel.Id), new AttributeValue(addProfileModel.Id)},
{nameof(AddProfileModel.Name), new AttributeValue(addProfileModel.Name)},
{nameof(AddProfileModel.Email), new AttributeValue(addProfileModel.Email)},
{nameof(AddProfileModel.ProfilePicName), new AttributeValue(addProfileModel.ProfilePicName)}
});
var response = new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.OK,
Body = "Created",
Headers = new Dictionary<string, string> { { "Content-Type", "text/plain" } }
};
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.