Skip to content

Commit 88d3947

Browse files
authored
Adding the CodePipelineEvent (#363)
* Adding the CodePipelineEvent * Added individual getters and setters as Jackson was not including revision in the output when null.
1 parent 34e5f42 commit 88d3947

File tree

6 files changed

+269
-0
lines changed

6 files changed

+269
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5+
* the License. A copy of the License is located at
6+
*
7+
* http://aws.amazon.com/apache2.0
8+
*
9+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
14+
package com.amazonaws.services.lambda.runtime.events;
15+
16+
import com.fasterxml.jackson.annotation.JsonInclude;
17+
import com.fasterxml.jackson.annotation.JsonProperty;
18+
import lombok.AllArgsConstructor;
19+
import lombok.Builder;
20+
import lombok.Data;
21+
import lombok.NoArgsConstructor;
22+
23+
import java.io.Serializable;
24+
import java.util.List;
25+
26+
/**
27+
* Represents an CodePipeline event sent to Lambda.
28+
* 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>
29+
*/
30+
@Data
31+
@Builder(setterPrefix = "with")
32+
@NoArgsConstructor
33+
@AllArgsConstructor
34+
public class CodePipelineEvent implements Serializable {
35+
private static final long serialVersionUID = -4828716548429210697L;
36+
37+
@JsonProperty("CodePipeline.job")
38+
private Job codePipelineJob;
39+
40+
@lombok.Data
41+
@Builder(setterPrefix = "with")
42+
@NoArgsConstructor
43+
@AllArgsConstructor
44+
public static class Job implements Serializable {
45+
private static final long serialVersionUID = 2211711169692638977L;
46+
47+
private String id;
48+
private String accountId;
49+
private Data data;
50+
}
51+
52+
@lombok.Data
53+
@Builder(setterPrefix = "with")
54+
@NoArgsConstructor
55+
@AllArgsConstructor
56+
public static class Data implements Serializable {
57+
private static final long serialVersionUID = 8786599041834868262L;
58+
59+
private ActionConfiguration actionConfiguration;
60+
private List<Artifact> inputArtifacts;
61+
private List<Artifact> outputArtifacts;
62+
private ArtifactCredentials artifactCredentials;
63+
private String continuationToken;
64+
private EncryptionKey encryptionKey;
65+
}
66+
67+
@lombok.Data
68+
@Builder(setterPrefix = "with")
69+
@NoArgsConstructor
70+
@AllArgsConstructor
71+
public static class ActionConfiguration implements Serializable {
72+
private static final long serialVersionUID = -7285651174501621217L;
73+
74+
private Configuration configuration;
75+
}
76+
77+
@lombok.Data
78+
@Builder(setterPrefix = "with")
79+
@NoArgsConstructor
80+
@AllArgsConstructor
81+
public static class Configuration implements Serializable {
82+
private static final long serialVersionUID = 580024317691702894L;
83+
84+
@JsonProperty("FunctionName")
85+
private String functionName;
86+
@JsonProperty("UserParameters")
87+
private String userParameters;
88+
}
89+
90+
@lombok.Data
91+
@Builder(setterPrefix = "with")
92+
@NoArgsConstructor
93+
@AllArgsConstructor
94+
public static class Artifact implements Serializable {
95+
private static final long serialVersionUID = 6406621244704594358L;
96+
97+
private String name;
98+
private String revision;
99+
private Location location;
100+
101+
@JsonInclude
102+
public String getRevision() {
103+
return revision;
104+
}
105+
106+
@JsonInclude
107+
public void setRevision(String revision) {
108+
this.revision = revision;
109+
}
110+
}
111+
112+
@lombok.Data
113+
@Builder(setterPrefix = "with")
114+
@NoArgsConstructor
115+
@AllArgsConstructor
116+
public static class Location implements Serializable {
117+
private static final long serialVersionUID = 149382199413534713L;
118+
119+
private String type;
120+
private S3Location s3Location;
121+
}
122+
123+
@lombok.Data
124+
@Builder(setterPrefix = "with")
125+
@NoArgsConstructor
126+
@AllArgsConstructor
127+
public static class S3Location implements Serializable {
128+
private static final long serialVersionUID = -8922449809993769709L;
129+
130+
private String bucketName;
131+
private String objectKey;
132+
}
133+
134+
@lombok.Data
135+
@Builder(setterPrefix = "with")
136+
@NoArgsConstructor
137+
@AllArgsConstructor
138+
public static class ArtifactCredentials implements Serializable {
139+
private static final long serialVersionUID = 7710347495607396747L;
140+
141+
private String accessKeyId;
142+
private String secretAccessKey;
143+
private String sessionToken;
144+
}
145+
146+
@lombok.Data
147+
@Builder(setterPrefix = "with")
148+
@NoArgsConstructor
149+
@AllArgsConstructor
150+
public static class EncryptionKey implements Serializable {
151+
private static final long serialVersionUID = -9105569908901180610L;
152+
153+
String id;
154+
String type;
155+
}
156+
}

aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/LambdaEventSerializersTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ public void testCodeCommitEvent() throws IOException, JSONException {
180180
assertEquals(expected, actual, STRICT);
181181
}
182182

183+
@Test
184+
public void testCodePipelineEvent() throws IOException, JSONException {
185+
String expected = EventUtils.readEvent("code_pipeline_event.json");
186+
String actual = deserializeSerializeJsonToString(expected, CodePipelineEvent.class);
187+
188+
assertEquals(expected, actual, STRICT);
189+
}
190+
183191
@Test
184192
public void testCognitoEvent() throws IOException, JSONException {
185193
String expected = EventUtils.readEvent("cognito_event.json");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"CodePipeline.job": {
3+
"id": "11111111-abcd-1111-abcd-111111abcdef",
4+
"accountId": "111111111111",
5+
"data": {
6+
"actionConfiguration": {
7+
"configuration": {
8+
"FunctionName": "MyLambdaFunctionForAWSCodePipeline",
9+
"UserParameters": "some-input-such-as-a-URL"
10+
}
11+
},
12+
"inputArtifacts": [
13+
{
14+
"location": {
15+
"s3Location": {
16+
"bucketName": "the name of the bucket configured as the pipeline artifact store in Amazon S3, for example codepipeline-us-east-2-1234567890",
17+
"objectKey": "the name of the application, for example CodePipelineDemoApplication.zip"
18+
},
19+
"type": "S3"
20+
},
21+
"revision": null,
22+
"name": "ArtifactName"
23+
}
24+
],
25+
"outputArtifacts": [],
26+
"artifactCredentials": {
27+
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
28+
"sessionToken": "MIICiTCCAfICCQD6m7oRw0uXOjANBgkqhkiG9wEXAMPLE=",
29+
"accessKeyId": "AKIAIOSFODNN7EXAMPLE"
30+
},
31+
"continuationToken": "A continuation token if continuing job",
32+
"encryptionKey": {
33+
"id": "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
34+
"type": "KMS"
35+
}
36+
}
37+
}
38+
}

aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public static CodeCommitEvent loadCodeCommitEvent(String filename) {
6161
return loadEvent(filename, CodeCommitEvent.class);
6262
}
6363

64+
public static CodePipelineEvent loadCodePipelineEvent(String filename) {
65+
return loadEvent(filename, CodePipelineEvent.class);
66+
}
67+
6468
public static ConfigEvent loadConfigEvent(String filename) {
6569
return loadEvent(filename, ConfigEvent.class);
6670
}

aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,31 @@ public void testLoadCodeCommitEvent() {
226226
assertThat(reference.getRef()).isEqualTo("refs/heads/master");
227227
}
228228

229+
@Test
230+
public void testLoadCodePipelineEvent() {
231+
CodePipelineEvent event = EventLoader.loadCodePipelineEvent("codepipeline_event.json");
232+
233+
assertThat(event).isNotNull();
234+
assertThat(event.getCodePipelineJob().getId()).isEqualTo("11111111-abcd-1111-abcd-111111abcdef");
235+
assertThat(event.getCodePipelineJob().getAccountId()).isEqualTo("111111111111");
236+
assertThat(event.getCodePipelineJob().getData().getActionConfiguration().getConfiguration().getFunctionName()).isEqualTo("MyLambdaFunctionForAWSCodePipeline");
237+
assertThat(event.getCodePipelineJob().getData().getActionConfiguration().getConfiguration().getUserParameters()).isEqualTo("some-input-such-as-a-URL");
238+
assertThat(event.getCodePipelineJob().getData().getInputArtifacts()).hasSize(1);
239+
assertThat(event.getCodePipelineJob().getData().getInputArtifacts().get(0).getLocation().getType()).isEqualTo("S3");
240+
assertThat(event.getCodePipelineJob().getData().getInputArtifacts().get(0).getLocation().getS3Location().getBucketName()).isEqualTo("the name of the bucket configured as the pipeline artifact store in Amazon S3, for example codepipeline-us-east-2-1234567890");
241+
assertThat(event.getCodePipelineJob().getData().getInputArtifacts().get(0).getLocation().getS3Location().getObjectKey()).isEqualTo("the name of the application, for example CodePipelineDemoApplication.zip");
242+
assertThat(event.getCodePipelineJob().getData().getInputArtifacts().get(0).getRevision()).isNull();
243+
assertThat(event.getCodePipelineJob().getData().getInputArtifacts().get(0).getName()).isEqualTo("ArtifactName");
244+
assertThat(event.getCodePipelineJob().getData().getOutputArtifacts()).hasSize(0);
245+
assertThat(event.getCodePipelineJob().getData().getArtifactCredentials().getSecretAccessKey()).isEqualTo("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY");
246+
assertThat(event.getCodePipelineJob().getData().getArtifactCredentials().getSessionToken()).isEqualTo("MIICiTCCAfICCQD6m7oRw0uXOjANBgkqhkiG9wEXAMPLE=");
247+
assertThat(event.getCodePipelineJob().getData().getArtifactCredentials().getAccessKeyId()).isEqualTo("AKIAIOSFODNN7EXAMPLE");
248+
assertThat(event.getCodePipelineJob().getData().getContinuationToken()).isEqualTo("A continuation token if continuing job");
249+
assertThat(event.getCodePipelineJob().getData().getEncryptionKey().getId()).isEqualTo("arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab");
250+
assertThat(event.getCodePipelineJob().getData().getEncryptionKey().getType()).isEqualTo("KMS");
251+
252+
}
253+
229254
@Test
230255
public void testLoadCloudWatchLogsEvent() {
231256
CloudWatchLogsEvent cloudWatchLogsEvent = EventLoader.loadCloudWatchLogsEvent("cloudwatchlogs_event.json");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"CodePipeline.job": {
3+
"id": "11111111-abcd-1111-abcd-111111abcdef",
4+
"accountId": "111111111111",
5+
"data": {
6+
"actionConfiguration": {
7+
"configuration": {
8+
"FunctionName": "MyLambdaFunctionForAWSCodePipeline",
9+
"UserParameters": "some-input-such-as-a-URL"
10+
}
11+
},
12+
"inputArtifacts": [
13+
{
14+
"location": {
15+
"s3Location": {
16+
"bucketName": "the name of the bucket configured as the pipeline artifact store in Amazon S3, for example codepipeline-us-east-2-1234567890",
17+
"objectKey": "the name of the application, for example CodePipelineDemoApplication.zip"
18+
},
19+
"type": "S3"
20+
},
21+
"revision": null,
22+
"name": "ArtifactName"
23+
}
24+
],
25+
"outputArtifacts": [],
26+
"artifactCredentials": {
27+
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
28+
"sessionToken": "MIICiTCCAfICCQD6m7oRw0uXOjANBgkqhkiG9wEXAMPLE=",
29+
"accessKeyId": "AKIAIOSFODNN7EXAMPLE"
30+
},
31+
"continuationToken": "A continuation token if continuing job",
32+
"encryptionKey": {
33+
"id": "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
34+
"type": "KMS"
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)