Skip to content

Instantly share code, notes, and snippets.

@awswithdotnet
awswithdotnet / GlobalUsings.g.cs
Created March 9, 2022 22:30
minimalapi GlobalUsings
// <auto-generated/>
global using global::Microsoft.AspNetCore.Builder;
global using global::Microsoft.AspNetCore.Hosting;
global using global::Microsoft.AspNetCore.Http;
global using global::Microsoft.AspNetCore.Routing;
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging;
global using global::System;
@awswithdotnet
awswithdotnet / Dockerfile
Created March 9, 2022 22:13
minimalapi Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS sdk
WORKDIR /app
COPY ./ ./
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=sdk /app/out .
ENTRYPOINT ["dotnet", "MinimalApi.dll"]
@awswithdotnet
awswithdotnet / Program.cs
Created March 9, 2022 22:07
minimalapi Program
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
WebApplication app = builder.Build();
app.MapGet("/greeting", () => "aws w/ .NET");
app.Run("http://*:80");
@awswithdotnet
awswithdotnet / MinimalApi.csproj
Created March 9, 2022 22:02
minimalapi MinimalApi.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
@awswithdotnet
awswithdotnet / Handler.cs
Created March 9, 2022 01:40
lambda Handler Handle
using System;
using Amazon.Lambda.CloudWatchEvents.ScheduledEvents;
using Amazon.Lambda.Core;
namespace simplelambda{
public class Handler
{
[LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
public void Handle(ScheduledEvent cloudWatchEvent)
@awswithdotnet
awswithdotnet / SQSMessageProducer.cs
Created March 9, 2022 01:10
sqs SQSMessageProducer Program
namespace SQSProducer
{
class Program
{
static async Task Main(string[] args)
{
var message = "New Message for " + DateTime.Now.ToString();
SQSMessageProducer sQSMessageProducer = new SQSMessageProducer();
@awswithdotnet
awswithdotnet / SQSMessageProducer.cs
Created March 9, 2022 01:08
sqs SQSMessageProducer Send
public async Task Send(String message)
{
string accessKey = "<AWS ACCESS KEY>";
string secret = "<AWS ACCESS KEY>";
string queueUrl = "<AWS ACCESS KEY>";
string awsregion = "<AWS ACCESS KEY>";
BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secret);
RegionEndpoint region = RegionEndpoint.GetBySystemName(awsregion);
@awswithdotnet
awswithdotnet / SQSMessageProducer.cs
Created March 9, 2022 01:07
sqs SQSMessageProducer Partial
namespace SQSProducer
{
public class SQSMessageProducer{
public SQSMessageProducer()
{
}
}
}
@awswithdotnet
awswithdotnet / Program.cs
Created March 8, 2022 20:41
kafka KafkaMessageProducer Program
namespace KafkaProducer
{
class Program
{
static void Main(string[] args)
{
var kafkaMessageProducer = new KafkaMessageProducer();
kafkaMessageProducer.Produce();
}
}
@awswithdotnet
awswithdotnet / KafkaMessageProducer.cs
Created March 8, 2022 20:40
kafka KafkaMessageProducer Partial 7
_producer = new ProducerBuilder<String, String>(config).Build();
_producer.Produce(_topic, new Message<string, string> { Key = Guid.NewGuid().ToString(), Value = "New Message: " + DateTime.Now.ToString() }, deliveryReportHandler);
_producer.Flush(TimeSpan.FromSeconds(_flushTime));