Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mikebroberts's full-sized avatar

Mike Roberts mikebroberts

View GitHub Profile
@mikebroberts
mikebroberts / template.yaml
Last active March 7, 2024 13:45
CloudFront Functions Demo with CloudFormation
Description: CloudFront Functions Demo
# This example shows how to use CloudFront, CloudFront Functions, and CloudFormation.
# In this simple example we setup CloudFront so that on any request we redirect to another site.
# While basic, this example can be expanded to provide typical redirect scenarios, based
# on the event passed to the function.
# This example written by Mike Roberts (https://twitter.com/mikebroberts), Symphonia.
# For more ideas about using AWS more effectively,see our blog at https://blog.symphonia.io/
@mikebroberts
mikebroberts / pipeline.yaml
Created January 2, 2019 19:08
Selectively triggering a GitHub sourced CodePipeline (only for one file)
# CodePipeline by default runs an execution whenever any change is detected in the configured source repository
# We can use a CodePipeline Webhook resource to filter such executions.
#
# This is a snippet that would be part of a CloudFormation template containing
# a CodePipeline resource (AWS::CodePipeline::Pipeline), named CodePipeline in this case, and
# assumes the GutHub OAuth token is available in the parameter GitHubOAuthToken.
# Typically a CodePipeline Webhook only contains the $.ref filter to check for
# the desired branch.
# However we can add up to 4 more filters, each of which can query the incoming webhook payload from Github.
# Such payloads are of the form:
@mikebroberts
mikebroberts / cdkApp.ts
Created April 28, 2022 20:35
Scheduled Step Function that calls a Lambda function, with backoff retry, in CDK
#!/usr/bin/env node
import 'source-map-support/register';
import {App, Duration, Stack, StackProps} from 'aws-cdk-lib';
import {Construct} from 'constructs';
import {Code, Function, Runtime} from "aws-cdk-lib/aws-lambda";
import {StateMachine} from "aws-cdk-lib/aws-stepfunctions";
import {LambdaInvoke} from "aws-cdk-lib/aws-stepfunctions-tasks";
import {Rule, RuleTargetInput, Schedule} from "aws-cdk-lib/aws-events";
import {SfnStateMachine} from "aws-cdk-lib/aws-events-targets";
@mikebroberts
mikebroberts / make-java-api.sh
Created April 3, 2017 15:27
Zero-to-production Java / Lambda / API Gateway script
#!/bin/bash
# Creates a Lambda and API Gateway proxying any verb on any path to lambda
#
# PREREQUISITES
#
# You must have the following installed locally: Java 8, mvn, AWS CLI
# Your AWS CLI must be configured for a user that has the necessary privileges
# You must have a basic role 'lambda_basic_execution' defined - this is what is created
# the first time you create a Lambda function in the web console
@mikebroberts
mikebroberts / slack.clj
Created March 17, 2014 18:02
Send a message to Slack incoming webhook in Clojure.
(ns slack
(:require [clj-http.client :as client]
[clojure.data.json :as json]))
(defn send-to-slack
"Sends a simple message to slack using an 'incoming webhook'.
url will be of form: https://myapp.slack.com/services/hooks/incoming-webhook?token=mytoken .
(Exact url you should use will appear on the slack integration page)
text will be any valid message.
This implementation could be expanded if you wanted to specify channel, username, etc.
AWSChatbotRole:
Type: AWS::IAM::Role
Properties:
RoleName: AWSChatbotRole
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: 'chatbot.amazonaws.com'
@mikebroberts
mikebroberts / gist:bd483a5079c90e55ed78e1ffacf7fe32
Created April 28, 2020 17:38
Thundra online debugging SAM template updates
diff --git a/chapter5-api/template.yaml b/chapter5-api/template.yaml
index 7c6e0a5..b47084a 100755
--- a/chapter5-api/template.yaml
+++ b/chapter5-api/template.yaml
@@ -41,6 +41,13 @@ Resources:
Properties:
CodeUri: target/lambda.zip
Handler: book.api.WeatherQueryLambda::handler
+ Timeout: 300
+ Layers:
@mikebroberts
mikebroberts / event.json
Created February 28, 2020 19:12
book-chapter-5-sample
{
"Records": [
{
"EventSubscriptionArn": "arn:aws:sns:us-east-1::ExampleTopic",
"Sns": {
"Type": "Notification",
"MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e",
"TopicArn": "arn:aws:sns:us-east-1:123456789012:ExampleTopic",
"Subject": "example subject",
"Message": "example message",
package io.symphonia;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoggingLambda {
// Configure our SLF4J Logger interface
private static final Logger LOG = LoggerFactory.getLogger(LoggingLambda.class);
public void handler(String s) {
<dependencies>
<dependency>
<groupId>io.symphonia</groupId>
<artifactId>lambda-logging</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>