Skip to content

Instantly share code, notes, and snippets.

Mike Roberts mikebroberts

Block or report user

Report or block mikebroberts

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mikebroberts
mikebroberts / pipeline.yaml
Created Jan 2, 2019
Selectively triggering a GitHub sourced CodePipeline (only for one file)
View pipeline.yaml
# 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:
View MyLambda.java
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.document.*;
public class MyLambda {
private final DynamoDB dynamoDB;
private final String tableName;
public MyLambda() {
this.dynamoDB = new DynamoDB(AmazonDynamoDBClientBuilder.defaultClient());
this.tableName = System.getenv("LOCATIONS_TABLE");
View MyLambda.java
public class MyLambda {
private static final String containerId = java.util.UUID.randomUUID().toString();
public String handler(String input) throws Exception {
Thread.sleep(5000);
return "This is function instance " + containerId;
}
}
View pom.xml
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.226</version>
</dependency>
</dependencies>
View MyLambda.java
public class MyLambda {
private static final String containerId = java.util.UUID.randomUUID().toString();
public String handler(String input) {
return "This is function instance " + containerId;
}
}
View MyLambda.java
public class MyLambda {
public String handler(Object input) {
return "Hello Lambda";
}
}
View S3LambdaError.java
public int containerExecutionCount = 0;
public void handler(Map<String, List<S3PutRecord>> input) {
final String key = input.get("Records").get(0).s3.object.key;
System.out.println("S3 PUT happened! Key was: " + key);
throw new RuntimeException("Throwing exception. This container has processed " + ++containerExecutionCount + " events");
}
@mikebroberts
mikebroberts / WhatIsMyLambdaEvent.java
Created Oct 24, 2017
Java AWS Lambda to log inbound event - useful when you don't know what structure an event has
View WhatIsMyLambdaEvent.java
package io.symphonia;
import java.io.InputStream;
import java.io.OutputStream;
public class WhatIsMyLambdaEvent {
public void handler(InputStream is, OutputStream os) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
System.out.println(s.hasNext() ? s.next() : "No input detected");
}
View MyHandler.java
public void handler(S3Put input) {
final String key = input.Records.get(0).s3.object.key;
System.out.println("S3 PUT happened! Key was: " + key);
}
View MyLambda.java
public class MyLambda {
public void handler(S3Put input) {
// Execution code will go here
}
public static class S3Put {
public java.util.List<S3PutRecord> Records;
public static class S3PutRecord {
public S3PutRecordS3 s3;
You can’t perform that action at this time.