Skip to content

Commit 5717b9e

Browse files
author
Michael Brewer
committed
docs(data-classes): Add docs for CodePipelineJobEvent
1 parent 0fe2397 commit 5717b9e

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

aws_lambda_powertools/utilities/data_classes/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .api_gateway_proxy_event import APIGatewayProxyEvent, APIGatewayProxyEventV2
77
from .appsync_resolver_event import AppSyncResolverEvent
88
from .cloud_watch_logs_event import CloudWatchLogsEvent
9+
from .code_pipeline_job_event import CodePipelineJobEvent
910
from .connect_contact_flow_event import ConnectContactFlowEvent
1011
from .dynamo_db_stream_event import DynamoDBStreamEvent
1112
from .event_bridge_event import EventBridgeEvent
@@ -21,6 +22,7 @@
2122
"AppSyncResolverEvent",
2223
"ALBEvent",
2324
"CloudWatchLogsEvent",
25+
"CodePipelineJobEvent",
2426
"ConnectContactFlowEvent",
2527
"DynamoDBStreamEvent",
2628
"EventBridgeEvent",

docs/utilities/data_classes.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Event Source | Data_class
5252
[API Gateway Proxy event v2](#api-gateway-proxy-v2) | `APIGatewayProxyEventV2`
5353
[AppSync Resolver](#appsync-resolver) | `AppSyncResolverEvent`
5454
[CloudWatch Logs](#cloudwatch-logs) | `CloudWatchLogsEvent`
55+
[CodePipeline Job Event](#codepipeline-job) | `CodePipelineJobEvent`
5556
[Cognito User Pool](#cognito-user-pool) | Multiple available under `cognito_user_pool_event`
5657
[Connect Contact Flow](#connect-contact-flow) | `ConnectContactFlowEvent`
5758
[DynamoDB streams](#dynamodb-streams) | `DynamoDBStreamEvent`, `DynamoDBRecordEventName`
@@ -222,6 +223,58 @@ decompress and parse json data from the event.
222223
do_something_with(event.timestamp, event.message)
223224
```
224225

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+
225278
### Cognito User Pool
226279

227280
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

tests/functional/test_data_classes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
APIGatewayProxyEventV2,
1414
AppSyncResolverEvent,
1515
CloudWatchLogsEvent,
16+
CodePipelineJobEvent,
1617
EventBridgeEvent,
1718
KinesisStreamEvent,
1819
S3Event,
@@ -34,7 +35,7 @@
3435
AppSyncResolverEventInfo,
3536
get_identity_object,
3637
)
37-
from aws_lambda_powertools.utilities.data_classes.code_pipeline_job_event import CodePipelineData, CodePipelineJobEvent
38+
from aws_lambda_powertools.utilities.data_classes.code_pipeline_job_event import CodePipelineData
3839
from aws_lambda_powertools.utilities.data_classes.cognito_user_pool_event import (
3940
CreateAuthChallengeTriggerEvent,
4041
CustomMessageTriggerEvent,

0 commit comments

Comments
 (0)