Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install buildx from docker/buildx-bin:latest #12

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aws-lambda-java-runtime-interface-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-serialization</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ private EventHandlerLoader() { }
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private static PojoSerializer<Object> getSerializer(Platform platform, Type type) {
PojoSerializer<Object> customSerializer = PojoSerializerLoader.getCustomerSerializer(type);
if (customSerializer != null) {
return customSerializer;
}

// if serializing a Class that is a Lambda supported event, use Jackson with customizations
if (type instanceof Class) {
Class<Object> clazz = ((Class)type);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. */

package com.amazonaws.services.lambda.runtime.api.client;

import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer;
import com.amazonaws.services.lambda.runtime.CustomPojoSerializer;

import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Iterator;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;

public class PojoSerializerLoader {
// The serializer obtained from the provider will always be the same so we can cache it as a filed.
private static CustomPojoSerializer customPojoSerializer;
// If Input and Output type are different, the runtime will try to search for a serializer twice due to
// the getSerializerCached method. Save the initialization state in order to search for the provider only once.
private static boolean initialized = false;

private static CustomPojoSerializer loadSerializer()
throws ServiceConfigurationError, TooManyServiceProvidersFoundException {

if (customPojoSerializer != null) {
return customPojoSerializer;
}

ServiceLoader<CustomPojoSerializer> loader = ServiceLoader.load(CustomPojoSerializer.class, AWSLambda.customerClassLoader);
Iterator<CustomPojoSerializer> serializers = loader.iterator();

if (!serializers.hasNext()) {
initialized = true;
return null;
}

customPojoSerializer = serializers.next();

if (serializers.hasNext()) {
throw new TooManyServiceProvidersFoundException(
"Too many serializers provided inside the META-INF/services folder, only one is allowed"
);
}

initialized = true;
return customPojoSerializer;
}

public static PojoSerializer<Object> getCustomerSerializer(Type type)
throws SerializersNotFoundException {

if (!initialized) {
customPojoSerializer = loadSerializer();
}

if (customPojoSerializer == null) {
return null;
}

return new PojoSerializer<Object>() {
@Override
public Object fromJson(InputStream input) {
return customPojoSerializer.fromJson(input, type);
}

@Override
public Object fromJson(String input) {
return customPojoSerializer.fromJson(input, type);
}

@Override
public void toJson(Object value, OutputStream output) {
customPojoSerializer.toJson(value, output, type);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. */

package com.amazonaws.services.lambda.runtime.api.client;

public class SerializersNotFoundException extends IllegalArgumentException {
public SerializersNotFoundException() {

}

public SerializersNotFoundException(String errorMessage) {
super(errorMessage);
}

public SerializersNotFoundException(Throwable cause) {
super(cause);
}

public SerializersNotFoundException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. */

package com.amazonaws.services.lambda.runtime.api.client;

public class TooManyServiceProvidersFoundException extends RuntimeException {
public TooManyServiceProvidersFoundException() {

}

public TooManyServiceProvidersFoundException(String errorMessage) {
super(errorMessage);
}

public TooManyServiceProvidersFoundException(Throwable cause) {
super(cause);
}

public TooManyServiceProvidersFoundException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
FROM public.ecr.aws/amazoncorretto/amazoncorretto:8

ARG ARCHITECTURE="amd64"

ENV DOCKER_CLI_PLUGIN_DIR="/root/.docker/cli-plugins"
ENV PATH="$PATH:/tmp/apache-maven-3.8.7/bin"

# Install docker and buildx extension
RUN amazon-linux-extras enable docker && \
yum clean metadata && \
yum install -y docker tar gzip unzip file wget
yum install -y docker tar gzip unzip file

RUN mkdir -p "${DOCKER_CLI_PLUGIN_DIR}"
RUN wget \
"$(curl https://api.github.com/repos/docker/buildx/releases/latest | grep browser_download_url | grep "linux-${ARCHITECTURE}" | cut -d '"' -f 4)" \
-O "${DOCKER_CLI_PLUGIN_DIR}"/docker-buildx
RUN chmod +x "${DOCKER_CLI_PLUGIN_DIR}"/docker-buildx
COPY --from=docker/buildx-bin:latest /buildx /usr/libexec/docker/cli-plugins/docker-buildx

WORKDIR /tmp
RUN curl -O https://archive.apache.org/dist/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz && \
tar xf apache-maven-3.8.7-bin.tar.gz
# Install maven from apache.org, as version in the yum repository doesn't support latest maven plugins
ENV PATH="$PATH:/apache-maven/bin"
RUN mkdir /apache-maven && \
curl https://archive.apache.org/dist/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz | \
tar -xz -C /apache-maven --strip-components 1
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,17 @@ set -euo pipefail
echo "Setting up multi-arch build environment"
ARCHITECTURE=$(arch)
if [[ "$ARCHITECTURE" == "x86_64" ]]; then
ARCHITECTURE_ALIAS="amd64"
TARGET_EMULATOR="arm64"
elif [[ "$ARCHITECTURE" == "aarch64" ]]; then
ARCHITECTURE_ALIAS="arm64"
TARGET_EMULATOR="amd64"
else
echo "Architecture $ARCHITECTURE is not currently supported."
exit 1
fi

echo "Installing ${TARGET_EMULATOR} emulator"
docker pull public.ecr.aws/eks-distro-build-tooling/binfmt-misc:qemu-v6.1.0
docker run --rm --privileged public.ecr.aws/eks-distro-build-tooling/binfmt-misc:qemu-v6.1.0 --install ${TARGET_EMULATOR}
# Install buildx plugin only if not already present (i.e. it's installed for the local-agent)
if [[ ! -f "${DOCKER_CLI_PLUGIN_DIR}/docker-buildx" ]]; then
echo "docker-buildx not found, installing now"
mkdir -p "${DOCKER_CLI_PLUGIN_DIR}"
BUILDX_URL=$(curl https://api.github.com/repos/docker/buildx/releases/latest | grep browser_download_url | grep "linux-${ARCHITECTURE_ALIAS}" | cut -d '"' -f 4)
wget "${BUILDX_URL}" -O "${DOCKER_CLI_PLUGIN_DIR}"/docker-buildx
chmod +x "${DOCKER_CLI_PLUGIN_DIR}"/docker-buildx
fi
echo "Setting docker build command to default to buildx"
echo "Docker buildx version: $(docker buildx version)"
docker buildx install
6 changes: 3 additions & 3 deletions aws-lambda-java-serialization/RELEASE.CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### November 21, 2022
`1.0.1`:
- Updated `jackson-databind` dependency from 2.12.6.1 to 2.13.4.1
### February 24, 2023
`1.0.1-java17`:
- Add support for tumbling windows events

### December 01, 2020
`1.0.0`:
Expand Down
8 changes: 5 additions & 3 deletions aws-lambda-java-serialization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-serialization</artifactId>
<version>1.0.1</version>
<version>1.0.1-java17</version>
<packaging>jar</packaging>

<name>AWS Lambda Java Runtime Serialization</name>
Expand Down Expand Up @@ -32,6 +32,8 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<relocation.prefix>com.amazonaws.lambda.thirdparty</relocation.prefix>
<jackson.version>2.10.5.1</jackson.version>
<gson.version>2.8.9</gson.version>
<junit.version>5.9.1</junit.version>
<owasp.version>7.3.2</owasp.version>
</properties>
Expand All @@ -41,12 +43,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.4.1</version>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
Expand Down