Skip to content

Instantly share code, notes, and snippets.

View skorfmann's full-sized avatar

Sebastian Korfmann skorfmann

View GitHub Profile
@skorfmann
skorfmann / Readme.md
Last active January 4, 2021 15:35
Stub Lambda Functions in your CDK Stack

Stubbing Lambda Functions in your CDK Stack

Given you have a stack with one or more Lambda functions (e.g. as part of a Step Functions state machine), it can be pretty useful to stub long running parts with a known response.

This makes use of cdk Aspects, which allows modifying all or a filtered subsset of resources for a given scope (Stack, Construct).

In addition this leverages raw overrides to remove the original code of the Lambda function.

Please note, that the stub has to be in Python or NodeJS, since inlining code is only supported by those runtimes.

@skorfmann
skorfmann / event-proxy-lambda.js
Last active September 2, 2022 12:09
AWS CDK EventBridge -> AppSync Subscriptions Proxy
const AWS = require('aws-sdk')
const appsync = require('aws-appsync');
const gql = require('graphql-tag');
require('cross-fetch/polyfill');
exports.handler = async function(event) {
const graphqlClient = new appsync.AWSAppSyncClient({
url: process.env.APPSYNC_ENDPOINT_URL,
region: process.env.AWS_REGION,
auth: {
import ecs = require('@aws-cdk/aws-ecs');
import { DockerImageAsset } from '@aws-cdk/aws-ecr-assets';
import path = require('path')
export interface FooFargateProps {
}
export class FooFargate extends cdk.Construct {
constructor(scope: cdk.Construct, id: string, props: FooFargateProps = {}) {
@skorfmann
skorfmann / Readme.md
Last active May 24, 2025 14:15
Private Api Gateway in CDK.

Private API Gateway with the AWS CDK

  • Lambda
  • Private Api Gateway
  • VPC Endpoint

NB: In order to access the Api Gateway through the public DNS of the VPC endpoint, a curl request has to have the api id as header. See also here

curl -i -H "x-apigw-api-id: " https://vpce-.execute-api..vpce.amazonaws.com/

Both things have been introduced recently, and let you access even private ec2 instances

  1. Without VPN
  2. No open SSH port
  3. Authentication / Authorization is fully delegated to IAM
# Assumes valid AWS Credentials in ENV
require 'dnsimple'
require 'platform-api'
namespace :staging do
desc "create subdomain DNS record for Heroku review app"
task :publish_dns do
heroku_app_name = ENV['HEROKU_APP_NAME']
heroku_app_name =~ /.*(pr-\d+)/
subdomain = $1
shared_examples 'included before filter' do |expected_filter, actions|
controller do
skip_filter *_process_action_callbacks.map(&:filter).reject {|filter| filter == expected_filter }
actions.each do |action|
define_method(action) do
render nothing: true
end
end
end
alias rs='rails server'
alias rc='rails console'
alias rg='rails generate'
alias r='ruby'
alias be='bundle exec'
alias gst='git status' # Show the status
alias gl='git pull --rebase' # Pull rebase
alias gp='git push' # Push
alias gu='git up' # Push

Howto Reset etcd discovery

Every time my test cluster is going down, I was struggeling with etcd autodiscovery failing. This looks probably familiar to you:

The Problem

systemd[1]: Starting etcd...
systemd[1]: Started etcd.
etcd[3066]: [etcd] Apr  9 08:31:42.512 INFO      | Discovery via https://discovery.etcd.io using prefix /<TOKEN>.