@@ -52,6 +52,7 @@ Event Source | Data_class
52
52
[ API Gateway Proxy event v2] ( #api-gateway-proxy-v2 ) | ` APIGatewayProxyEventV2 `
53
53
[ AppSync Resolver] ( #appsync-resolver ) | ` AppSyncResolverEvent `
54
54
[ CloudWatch Logs] ( #cloudwatch-logs ) | ` CloudWatchLogsEvent `
55
+ [ CodePipeline Job Event] ( #codepipeline-job ) | ` CodePipelineJobEvent `
55
56
[ Cognito User Pool] ( #cognito-user-pool ) | Multiple available under ` cognito_user_pool_event `
56
57
[ Connect Contact Flow] ( #connect-contact-flow ) | ` ConnectContactFlowEvent `
57
58
[ DynamoDB streams] ( #dynamodb-streams ) | ` DynamoDBStreamEvent ` , ` DynamoDBRecordEventName `
@@ -222,6 +223,58 @@ decompress and parse json data from the event.
222
223
do_something_with(event.timestamp, event.message)
223
224
```
224
225
226
+ ### CodePipeline Job
227
+
228
+ Data classes and utility functions to help create continuous delivery pipelines tasks with AWS Lambda
229
+
230
+ === "app.py"
231
+
232
+ ```python
233
+ from aws_lambda_powertools import Logger
234
+ from aws_lambda_powertools.utilities.data_classes import CodePipelineJobEvent
235
+
236
+ logger = Logger()
237
+
238
+
239
+ def lambda_handler(event, context):
240
+ """The Lambda function handler
241
+
242
+ If a continuing job then checks the CloudFormation stack status
243
+ and updates the job accordingly.
244
+
245
+ If a new job then kick of an update or creation of the target
246
+ CloudFormation stack.
247
+ """
248
+ event: CodePipelineJobEvent = CodePipelineJobEvent(event)
249
+
250
+ # Extract the Job ID
251
+ job_id = event.get_id
252
+
253
+ # Extract the params
254
+ params: dict = event.decoded_user_parameters
255
+ stack = params["stack"]
256
+ artifact_name = params["artifact"]
257
+ template_file = params["file"]
258
+
259
+ try:
260
+ if event.data.continuation_token:
261
+ # If we're continuing then the create/update has already been triggered
262
+ # we just need to check if it has finished.
263
+ check_stack_update_status(job_id, stack)
264
+ else:
265
+ template = event.get_artifact(artifact_name, template_file)
266
+ # Kick off a stack update or create
267
+ start_update_or_create(job_id, stack, template)
268
+ except Exception as e:
269
+ # If any other exceptions which we didn't expect are raised
270
+ # then fail the job and log the exception message.
271
+ logger.exception("Function failed due to exception.")
272
+ put_job_failure(job_id, "Function exception: " + str(e))
273
+
274
+ logger.debug("Function complete.")
275
+ return "Complete."
276
+ ```
277
+
225
278
### Cognito User Pool
226
279
227
280
Cognito User Pools have several [ different Lambda trigger sources] ( https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html#cognito-user-identity-pools-working-with-aws-lambda-trigger-sources ) , all of which map to a different data class, which
0 commit comments