Skip to content

Commit e011008

Browse files
committed
Adding in creation complete event to state machine
Ignoring check I3042 for cfn-lint Adding in EventBus to deployment account Adding in x-ray tracing to pipeline management lambda functions Changing event content, adding in xray layer to pipeline management lambda functions Documentation Mega Lint Fixes Forgot to hit save :(
1 parent 3452301 commit e011008

File tree

18 files changed

+150
-10
lines changed

18 files changed

+150
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ within the AWS Console.
3636
- Refer to the [User Guide](docs/user-guide.md) for using ADF once it is setup.
3737
- Refer to the [Samples Guide](docs/samples-guide.md) for a detailed walk
3838
through of the provided samples.
39+
- Refer to the [Integrations Guide](docs/integrations-guide.md) for information on events produced by the ADF.

docs/integrations-guide.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Integrations Guide
2+
## Introduction
3+
The AWS Deployment Framework enables integrations with external workflows via an Event Bus deployed into the organisational root account.
4+
5+
## Account Management Events
6+
The account management events are emitted at various stages during an execution of the Account Management State Machine.
7+
Currently - events are emitted for the following states:
8+
- ACCOUNT_PROVISIONED
9+
Emitted when an AWS account is created.
10+
Contains the account definition from the .yml file as well as the account_id.
11+
- ENTERPRISE_SUPPORT_REQUESTED
12+
Emitted when the support ticket to AWS Support is raised.
13+
Contains the account definition from the .yml file as well as the account_id.
14+
- ACCOUNT_ALIAS_CONFIGURED
15+
Emitted when the accounts alias is configured by ADF.
16+
The details section contains the account id and the alias value. The resource field also contains the account id
17+
- ACCOUNT_TAGS_CONFIGURED
18+
Emitted when the accounts tags are updated by ADF.
19+
The details section contains the account id and the tags. The resource field also contains the account id
20+
- DEFAULT_VPC_DELETED
21+
Emitted when the default VPC in a region is deleted.
22+
The details section contains the account id and the region of the VPC. The resource field contains the deleted VPC id.
23+
- ACCOUNT_CREATION_COMPLETE
24+
Emitted when the state machine completes successfully.
25+
Contains the account definition from the .yml file as well as the account_id in the resource field.
26+
27+
28+
29+
30+
## Pipeline Management Events
31+
- CROSS_ACCOUNT_RULE_CREATED_OR_UPDATED
32+
Emitted when a rule is created to trigger pipelines from a different account.
33+
The details sections contains the source_account_id (The account where the CodeCommit repository is located) and the resource sections contains the deployment account Id (The account where the CodePipeline is located)
34+
- REPOSITORY_CREATED_OR_UPDATED
35+
Emitted when a codecommit repository is created in a different account than the deployment account.
36+
The details sections contains the repository_account_id (The account where the CodeCommit repository is located) as well as the stack_name (The CloudFormation stack that creates the repository) and the resource sections contains the repository account Id and the pipeline name
37+
38+

src/lambda_codebase/account_processing/configure_account_alias.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
LOGGER = configure_logger(__name__)
1919
ADF_ROLE_NAME = os.getenv("ADF_ROLE_NAME")
2020
AWS_PARTITION = os.getenv("AWS_PARTITION")
21-
EVENTS = ADFEvents(boto3.client("events"), "AccountManagement.Alias")
21+
EVENTS = ADFEvents(boto3.client("events"), "AccountManagement")
2222

2323

2424
def delete_account_aliases(account, iam_client, current_aliases):
@@ -80,7 +80,7 @@ def lambda_handler(event, _):
8080
"adf_account_alias_config",
8181
)
8282
ensure_account_has_alias(event, role.client("iam"))
83-
EVENTS.put_event(detail=json.dumps(event), detailType="ACCOUNT_ALIAS_CONFIGURED", resources=[account_id])
83+
EVENTS.put_event(detail=json.dumps({"account_id": account_id, "alias_value": event.get("alias")}), detailType="ACCOUNT_ALIAS_CONFIGURED", resources=[account_id])
8484
else:
8585
LOGGER.info(
8686
"Account: %s does not need an alias",

src/lambda_codebase/account_processing/configure_account_tags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from events import ADFEvents
2020

2121
patch_all()
22-
EVENTS = ADFEvents(boto3.client("events"), "AccountManagement.Tags")
22+
EVENTS = ADFEvents(boto3.client("events"), "AccountManagement")
2323
LOGGER = configure_logger(__name__)
2424

2525

@@ -40,7 +40,7 @@ def lambda_handler(event, _):
4040
event.get("tags"),
4141
organizations,
4242
)
43-
EVENTS.put_event(detail=json.dumps(event), detailType="ACCOUNT_TAGS_CONFIGURED", resources=[event.get('account_id')])
43+
EVENTS.put_event(detail=json.dumps({"tags": event.get("tags"), "account_id": event.get("account_id")}), detailType="ACCOUNT_TAGS_CONFIGURED", resources=[event.get('account_id')])
4444
else:
4545
LOGGER.info(
4646
"Account: %s does not need tags configured",

src/lambda_codebase/account_processing/create_account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
LOGGER = configure_logger(__name__)
2020
ADF_ROLE_NAME = os.getenv("ADF_ROLE_NAME")
21-
EVENTS = ADFEvents(boto3.client("events"), "AccountManagement.AccountProvisioning")
21+
EVENTS = ADFEvents(boto3.client("events"), "AccountManagement")
2222

2323

2424

src/lambda_codebase/account_processing/delete_default_vpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
LOGGER = configure_logger(__name__)
1818
ADF_ROLE_NAME = os.getenv("ADF_ROLE_NAME")
1919
AWS_PARTITION = os.getenv("AWS_PARTITION")
20-
EVENTS = ADFEvents(boto3.client("events"), "AccountManagement.VPC")
20+
EVENTS = ADFEvents(boto3.client("events"), "AccountManagement")
2121

2222

2323

@@ -84,7 +84,7 @@ def lambda_handler(event, _):
8484
)
8585
ec2_resource = role.resource("ec2", region_name=event.get("region"))
8686
delete_default_vpc(ec2_resource, ec2_client, default_vpc_id)
87-
EVENTS.put_event(detail=json.dumps(event), detailType="DEFAULT_VPC_DELETED", resources=[event.get("account_id"), default_vpc_id])
87+
EVENTS.put_event(detail=json.dumps({"region": event.get("region"), "account_id":event.get("account_id")}), detailType="DEFAULT_VPC_DELETED", resources=[default_vpc_id])
8888

8989

9090
return {"Payload": event}

src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/deployment/global.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ Globals:
6969
CodeUri: lambda_codebase
7070
Runtime: python3.9
7171

72+
Mappings:
73+
OrganisationPartitionRegionMapping:
74+
aws:
75+
region: "us-east-1"
76+
aws-us-gov:
77+
region: "us-gov-west-1"
78+
7279
Resources:
7380
LambdaLayerVersion:
7481
Type: "AWS::Serverless::LayerVersion"
@@ -183,6 +190,7 @@ Resources:
183190
CrossAccountAccessRole: !Ref CrossAccountAccessRole
184191
PipelineBucket: !Ref PipelineBucket
185192
RootAccountId: !Ref MasterAccountId
193+
RootAccountRegion: !FindInMap [OrganisationPartitionRegionMapping, !Ref "AWS::Partition", "region"]
186194
CodeBuildImage: !Ref Image
187195
CodeBuildComputeType: !Ref ComputeType
188196
SharedModulesBucket: !Ref SharedModulesBucket

src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/deployment/lambda_codebase/pipeline_management/create_or_update_rule.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@
55
"""
66

77
import os
8+
import json
89
import boto3
910

1011
from cache import Cache
1112
from rule import Rule
1213
from logger import configure_logger
1314
from cloudwatch import ADFMetrics
15+
from events import ADFEvents
16+
from aws_xray_sdk.core import patch_all
1417

1518

19+
patch_all()
1620
LOGGER = configure_logger(__name__)
1721
DEPLOYMENT_ACCOUNT_REGION = os.environ["AWS_REGION"]
1822
DEPLOYMENT_ACCOUNT_ID = os.environ["ACCOUNT_ID"]
1923
PIPELINE_MANAGEMENT_STATEMACHINE = os.getenv("PIPELINE_MANAGEMENT_STATEMACHINE_ARN")
2024
CLOUDWATCH = boto3.client("cloudwatch")
2125
METRICS = ADFMetrics(CLOUDWATCH, "PIPELINE_MANAGEMENT/RULE")
26+
EVENTS = ADFEvents(boto3.client("events", region_name=os.getenv("ADF_EVENTBUS_REGION")), "PipelineManagement")
2227

2328
_cache = None
2429

@@ -56,5 +61,6 @@ def lambda_handler(pipeline, _):
5661
METRICS.put_metric_data(
5762
{"MetricName": "CreateOrUpdate", "Value": 1, "Unit": "Count"}
5863
)
64+
EVENTS.put_event(detail=json.dumps({"source_account_id": _source_account_id}), detailType="CROSS_ACCOUNT_RULE_CREATED_OR_UPDATED", resources=[DEPLOYMENT_ACCOUNT_ID])
5965

6066
return pipeline

src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/deployment/lambda_codebase/pipeline_management/create_repository.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
"""
55

66
import os
7+
import json
78
import boto3
89
from repo import Repo
910

1011
from logger import configure_logger
1112
from cloudwatch import ADFMetrics
1213
from parameter_store import ParameterStore
14+
from events import ADFEvents
1315

1416

1517
CLOUDWATCH = boto3.client("cloudwatch")
1618
METRICS = ADFMetrics(CLOUDWATCH, "PIPELINE_MANAGEMENT/REPO")
1719
LOGGER = configure_logger(__name__)
1820
DEPLOYMENT_ACCOUNT_REGION = os.environ["AWS_REGION"]
1921
DEPLOYMENT_ACCOUNT_ID = os.environ["ACCOUNT_ID"]
22+
EVENTS = ADFEvents(boto3.client("events", region_name=os.getenv("ADF_EVENTBUS_REGION")), "PipelineManagement")
23+
2024

2125

2226
def lambda_handler(pipeline, _):
@@ -52,5 +56,15 @@ def lambda_handler(pipeline, _):
5256
METRICS.put_metric_data(
5357
{"MetricName": "CreateOrUpdate", "Value": 1, "Unit": "Count"}
5458
)
59+
EVENTS.put_event(
60+
detail=json.dumps({
61+
"repository_account_id": code_account_id,
62+
"stack_name": repo.stack_name
63+
}),
64+
detailType="REPOSITORY_CREATED_OR_UPDATED",
65+
resources=[
66+
f'{code_account_id}:{pipeline.get("name")}'
67+
]
68+
)
5569

5670
return pipeline

src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/deployment/lambda_codebase/pipeline_management/generate_pipeline_inputs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
from sts import STS
1414
from logger import configure_logger
1515
from partition import get_partition
16+
from aws_xray_sdk.core import patch_all
1617

1718

19+
patch_all()
1820
LOGGER = configure_logger(__name__)
1921
DEPLOYMENT_ACCOUNT_REGION = os.environ["AWS_REGION"]
2022
DEPLOYMENT_ACCOUNT_ID = os.environ["ACCOUNT_ID"]

0 commit comments

Comments
 (0)