Skip to content

Instantly share code, notes, and snippets.

View bruceharrison1984's full-sized avatar
🔥

Bruce Harrison bruceharrison1984

🔥
View GitHub Profile
@bruceharrison1984
bruceharrison1984 / simple-example.cs
Last active October 14, 2024 21:27
TinyHealthCheck Simple Example
public static IHostBuilder CreateHostBuilder(string[] args)
{
var processStartTime = DateTimeOffset.Now;
return Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
services.AddBasicTinyHealthCheckWithUptime(config =>
{
config.Port = 8081;
@bruceharrison1984
bruceharrison1984 / rabbitmq-cloudformation.yml
Last active March 17, 2023 01:00
RabbitMQ CloudFormation Template
AWSTemplateFormatVersion: "2010-09-09"
Description: AWS CloudFormation template to launch an AmazonMQ(RabbitMQ) instance. Specifying anything larger than mq.t3.micro will deploy a cluster instead of a single-instance.
Parameters:
ClusterName:
Description: The name of the RabbitMQ Cluster
Type: String
MinLength: 8
MaxLength: 50
Subnets:
using System;
using System.Data.Common;
using System.Text.RegularExpressions;
using Amazon.Runtime.Internal.Util;
using Amazon.XRay.Recorder.Core;
using System.Configuration;
// copied from https://github.com/aws/aws-xray-sdk-dotnet/blob/d2b64125ecdd734af220795d5b102bd96b037981/sdk/src/Handlers/EntityFramework/EFUtil.cs#L58
// Xray doesn't support EF5 OOTB right now, so this lets us hack it back in
// code is a little hacked up to get support working without having to drag in a bunch of internal deps
using Microsoft.EntityFrameworkCore.Diagnostics;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
// copied from https://github.com/aws/aws-xray-sdk-dotnet/blob/master/sdk/src/Handlers/EntityFramework/EFInterceptor.cs
// Xray doesn't support EF5 OOTB right now, so this lets us hack it back in.
// All we did was change all the Task<> to ValueTask<>
namespace MyProject.Data
resource "aws_ecs_task_definition" "bastion" {
family = "${var.base_name}-bastion-task"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = 256
memory = 512
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
container_definitions = jsonencode([{
name = "bastion"
@bruceharrison1984
bruceharrison1984 / aws-secrets-manager-terraform-usage.tf
Last active March 2, 2021 15:43
Usage of aws-secrets-manager-terraform.tf
module "secrets" {
source = "./secrets"
base_name = local.base_name
default_tags = local.default_tags
secret_map = {
"shared/bastion/ssh/public_pem" = tls_private_key.bastion.public_key_openssh
"shared/bastion/ssh/private_pem" = tls_private_key.bastion.private_key_pem
"shared/bastion/ssh/username" = random_pet.bastion_username.id
}
@bruceharrison1984
bruceharrison1984 / aws-secrets-manager-terraform.tf
Last active March 2, 2021 15:42
Bulk save AWS Secrets with Terraform
variable "base_name" {
description = "The prefix on created resources"
}
variable "secret_map" {
description = "A Key/Value map of secrets that will be added to AWS Secrets"
type = map(string)
}
variable "default_tags" {
@bruceharrison1984
bruceharrison1984 / WebApi-Error-Middleware.cs
Created January 16, 2021 20:33
Example of how to implement global error handling in WebApi
using System;
using FluentValidation;
using System.Text.Json;
using System.Threading.Tasks;
using Logic.Exceptions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
using System.Linq;
using System.Collections.Generic;
@bruceharrison1984
bruceharrison1984 / azure-synapse-online-status.cs
Last active November 4, 2020 18:25
Check if Azure Synapse is Online
using Azure.Identity;
using Azure.ResourceManager.Resources;
using MyFunctionProject.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@bruceharrison1984
bruceharrison1984 / get_terraform_outputs.ps1
Last active July 17, 2020 22:04
Get outputs from terraform.io
param(
[string]$workspaceName = $(throw "Please specify a workspace name"),
[string]$organizationName = $(throw "Please specify an organization name"),
[string]$terraformIoToken = $(throw "Please specify a terraform Io Token")
)
$ErrorActionPreference = "Stop"
$baseUri = "https://app.terraform.io/"
$authHeader = @{ Authorization = "Bearer $terraformIoToken" }