Skip to content

Instantly share code, notes, and snippets.

@philipp94831
philipp94831 / S3BackedSerdeExample.java
Last active February 19, 2020 13:17
Example of S3BackedSerde as default SerDe
package com.bakdata.kafka;
import java.util.Properties;
import org.apache.kafka.common.serialization.Serdes.StringSerde;
import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.Topology;
import org.apache.kafka.streams.kstream.KStream;
@philipp94831
philipp94831 / S3BackedSerdeExample.java
Last active February 19, 2020 13:17
Example of S3BackedSerde
package com.bakdata.kafka;
import java.util.Map;
import java.util.Properties;
import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.common.serialization.Serdes.StringSerde;
import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.StreamsConfig;
@philipp94831
philipp94831 / FluentKafkaStreamsExampleTest.java
Created December 18, 2019 14:48
Fluent Kafka Streams Tests with AssertJ
package com.bakdata.kafka;
import static org.assertj.core.api.Assertions.assertThat;
import com.bakdata.fluent_kafka_streams_tests.junit5.TestTopologyExtension;
import com.google.common.collect.Lists;
import java.util.Properties;
import org.apache.kafka.common.serialization.Serdes.IntegerSerde;
import org.apache.kafka.common.serialization.Serdes.StringSerde;
import org.apache.kafka.streams.StreamsBuilder;
aws lambda invoke --function-name r-matrix-example \
--region eu-central-1 response.txt
cat response.txt
# {"result":[4,5,6]}
chmod 755 matrix.r
zip function.zip matrix.r
aws lambda create-function --function-name r-matrix-example \
--zip-file fileb://function.zip --handler matrix.handler \
--runtime provided --timeout 60 --memory-size 3008 \
--layers arn:aws:lambda:eu-central-1:131329294410:layer:r-runtime:10 \
arn:aws:lambda:eu-central-1:131329294410:layer:r-recommended:1 \
--role <role-arn> --region eu-central-1
aws lambda invoke --function-name r-example \
--payload '{"x":1}' --region eu-central-1 response.txt
cat response.txt
# {"result":2}
chmod 755 script.r
zip function.zip script.r
aws lambda create-function --function-name r-example \
--zip-file fileb://function.zip --handler script.increment \
--runtime provided --timeout 60 \
--layers arn:aws:lambda:eu-central-1:131329294410:layer:r-runtime:10 \
--role <role-arn> --region eu-central-1
library(Matrix)
handler <- function() {
return(Matrix(1:6, 3, 2)[, 2])
}
library(httr)
library(jsonlite)
HANDLER <- Sys.getenv("_HANDLER")
AWS_LAMBDA_RUNTIME_API <- Sys.getenv("AWS_LAMBDA_RUNTIME_API")
args = commandArgs(trailingOnly = TRUE)
EVENT_DATA <- args[1]
REQUEST_ID <- args[2]
HANDLER_split <- strsplit(HANDLER, ".", fixed = TRUE)[[1]]
#!/bin/sh
set -euo pipefail
# Processing
while true
do
HEADERS="$(mktemp)"
# Get an event
EVENT_DATA=$(curl -sS -LD "$HEADERS" -X GET \