Skip to content

adding codepipeline event (issue #16) #201

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

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.amazonaws.services.lambda.runtime.events;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
* Represents an CodePipeline event sent to Lambda.
* See: <a href="https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html">Invoke an AWS Lambda function in a pipeline in CodePipeline</a>
*/
@lombok.Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public class CodePipelineEvent implements Cloneable, Serializable {
private static final long serialVersionUID = -4828716548429210697L;

private Job codePipelineJob;

@lombok.Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class Job implements Serializable, Cloneable {
private static final long serialVersionUID = 2211711169692638977L;

private String id;
private String accountId;
private Data data;
}

@lombok.Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class Data implements Serializable, Cloneable {
private static final long serialVersionUID = 8786599041834868262L;

private ActionConfiguration actionConfiguration;
private List<Artifact> inputArtifacts;
private List<Artifact> outputArtifacts;
private ArtifactCredentials artifactCredentials;
private String continuationToken;
private EncryptionKey encryptionKey;
}

@lombok.Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class ActionConfiguration implements Serializable, Cloneable {
private static final long serialVersionUID = -7285651174501621217L;

private Configuration configuration;
}

@lombok.Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class Configuration implements Serializable, Cloneable {
private static final long serialVersionUID = 580024317691702894L;

private String functionName;
private String userParameters;
}

@lombok.Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class Artifact implements Serializable, Cloneable {
private static final long serialVersionUID = 6406621244704594358L;

private String name;
private String revision;
private Location location;
}

@lombok.Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class Location implements Serializable, Cloneable {
private static final long serialVersionUID = 149382199413534713L;

private String type;
private S3Location s3Location;
}

@lombok.Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class S3Location implements Serializable, Cloneable {
private static final long serialVersionUID = -8922449809993769709L;

private String bucketName;
private String objectKey;
}

@lombok.Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class ArtifactCredentials implements Serializable, Cloneable {
private static final long serialVersionUID = 7710347495607396747L;

private String accessKeyId;
private String secretAccessKey;
private String sessionToken;
private long expirationTime;
}

@lombok.Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(setterPrefix = "with")
public static class EncryptionKey implements Serializable, Cloneable {
private static final long serialVersionUID = -9105569908901180610L;

String id;
String type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

package com.amazonaws.services.lambda.runtime.serialization.events;

import com.amazonaws.services.lambda.runtime.serialization.events.mixins.CloudFormationCustomResourceEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.CloudFrontEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.CloudWatchLogsEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.CodeCommitEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.ConnectEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.DynamodbEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.KinesisEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.SNSEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.SQSEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.ScheduledEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.SecretsManagerRotationEventMixin;
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.*;
import com.amazonaws.services.lambda.runtime.serialization.factories.JacksonFactory;
import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer;
import com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil;
Expand Down Expand Up @@ -59,6 +49,7 @@ public class LambdaEventSerializers {
"com.amazonaws.services.lambda.runtime.events.CloudFrontEvent",
"com.amazonaws.services.lambda.runtime.events.CloudWatchLogsEvent",
"com.amazonaws.services.lambda.runtime.events.CodeCommitEvent",
"com.amazonaws.services.lambda.runtime.events.CodePipelineEvent",
"com.amazonaws.services.lambda.runtime.events.CognitoEvent",
"com.amazonaws.services.lambda.runtime.events.ConfigEvent",
"com.amazonaws.services.lambda.runtime.events.ConnectEvent",
Expand Down Expand Up @@ -106,6 +97,10 @@ public class LambdaEventSerializers {
CodeCommitEventMixin.class),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.CodeCommitEvent$Record",
CodeCommitEventMixin.RecordMixin.class),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.CodePipelineEvent",
CodePipelineEventMixin.class),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.CodePipelineEvent$Configuration",
CodePipelineEventMixin.ConfigurationMixin.class),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.ConnectEvent",
ConnectEventMixin.class),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.ConnectEvent$Details",
Expand Down Expand Up @@ -154,6 +149,9 @@ public class LambdaEventSerializers {
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.CodeCommitEvent",
Arrays.asList(
new NestedClass("com.amazonaws.services.lambda.runtime.events.CodeCommitEvent$Record"))),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.CodePipelineEvent",
Arrays.asList(
new NestedClass("com.amazonaws.services.lambda.runtime.events.CodePipelineEvent$Configuration"))),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.CognitoEvent",
Arrays.asList(
new NestedClass("com.amazonaws.services.lambda.runtime.events.CognitoEvent$DatasetRecord"))),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.amazonaws.services.lambda.runtime.serialization.events.mixins;

import com.fasterxml.jackson.annotation.JsonProperty;

public abstract class CodePipelineEventMixin {

// needed because Jackson expects "codePipelineJob" instead of "CodePipeline.job"
@JsonProperty("CodePipeline.job") abstract Object getCodePipelineJob();
@JsonProperty("CodePipeline.job") abstract void setCodePipelineJob(Object job);

public abstract static class ConfigurationMixin {
// needed because Jackson expects "functionName" instead of "FunctionName"
@JsonProperty("FunctionName") abstract String getFunctionName();
@JsonProperty("FunctionName") abstract void setFunctionName(String functionName);

// needed because Jackson expects "userParameters" instead of "UserParameters"
@JsonProperty("UserParameters") abstract String getUserParameters();
@JsonProperty("UserParameters") abstract void setUserParameters(String userParameters);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public static CodeCommitEvent loadCodeCommitEvent(String filename) {
return loadEvent(filename, CodeCommitEvent.class);
}

public static CodePipelineEvent loadCodePipelineEvent(String filename) {
return loadEvent(filename, CodePipelineEvent.class);
}

public static ConfigEvent loadConfigEvent(String filename) {
return loadEvent(filename, ConfigEvent.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ public void testLoadCodeCommitEvent() {
assertThat(reference.getRef()).isEqualTo("refs/heads/master");
}

@Test
public void testLoadCodePipelineEvent() {
CodePipelineEvent event = EventLoader.loadCodePipelineEvent("codepipeline_event.json");
assertThat(event).isNotNull();
assertThat(event.getCodePipelineJob()).isNotNull();
assertThat(event.getCodePipelineJob().getData().getActionConfiguration().getConfiguration().getFunctionName()).isEqualTo("my-function");
assertThat(event.getCodePipelineJob().getData().getActionConfiguration().getConfiguration().getUserParameters()).isEqualTo("{\"KEY\": \"VALUE\"}");
assertThat(event.getCodePipelineJob().getData().getArtifactCredentials().getAccessKeyId()).isEqualTo("AKIAIOSFODNN7EXAMPLE");
assertThat(event.getCodePipelineJob().getData().getInputArtifacts().get(0).getLocation().getS3Location().getBucketName()).isEqualTo("us-west-2-123456789012-my-pipeline");
assertThat(event.getCodePipelineJob().getData().getOutputArtifacts().get(0).getLocation().getS3Location().getObjectKey()).isEqualTo("my-pipeline/invokeOutp/D0YHsJn");
}

@Test
public void testLoadCloudWatchLogsEvent() {
CloudWatchLogsEvent cloudWatchLogsEvent = EventLoader.loadCloudWatchLogsEvent("cloudwatchlogs_event.json");
Expand Down
46 changes: 46 additions & 0 deletions aws-lambda-java-tests/src/test/resources/codepipeline_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"CodePipeline.job": {
"id": "c0d76431-b0e7-xmpl-97e3-e8ee786eb6f6",
"accountId": "123456789012",
"data": {
"actionConfiguration": {
"configuration": {
"FunctionName": "my-function",
"UserParameters": "{\"KEY\": \"VALUE\"}"
}
},
"inputArtifacts": [
{
"name": "my-pipeline-SourceArtifact",
"revision": "e0c7xmpl2308ca3071aa7bab414de234ab52eea",
"location": {
"type": "S3",
"s3Location": {
"bucketName": "us-west-2-123456789012-my-pipeline",
"objectKey": "my-pipeline/test-api-2/TdOSFRV"
}
}
}
],
"outputArtifacts": [
{
"name": "invokeOutput",
"revision": null,
"location": {
"type": "S3",
"s3Location": {
"bucketName": "us-west-2-123456789012-my-pipeline",
"objectKey": "my-pipeline/invokeOutp/D0YHsJn"
}
}
}
],
"artifactCredentials": {
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"secretAccessKey": "6CGtmAa3lzWtV7a...",
"sessionToken": "IQoJb3JpZ2luX2VjEA...",
"expirationTime": 1575493418000
}
}
}
}