Skip to content

Commit 20434e6

Browse files
committed
feat: Add rules for Amazon Q CLI
1 parent 8d907e5 commit 20434e6

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Lambda Layer in Python
2+
3+
## Purpose
4+
5+
This rule manages features to process CloudTrail log by event name.
6+
7+
## Instructions
8+
9+
* Please refer the rule of a CloudTrail event: https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-events.html
10+
* Get AWS service name from `eventSource` in the event. If `eventSource` is "cloudtrail.amazonaws.com", use "cloudtrail" before "amazonaws.com". (ID: SERVICE_NAME)
11+
* Create a file if `layer/python/cloudtrail_watcher/services/SERVICE_NAME.py` doesn't exist. File structure is below. (ID: SERVICE_FILE)
12+
13+
```python
14+
import boto3
15+
16+
from .common import *
17+
18+
SERVICE_NAME = boto3.client('SERVICE_NAME')
19+
20+
def process_event(event: dict, set_tag: bool = False) -> dict:
21+
""" Process CloudTrail event for SERVICE_NAME """
22+
23+
result = dict()
24+
25+
return result
26+
```
27+
28+
* Get the name of the event from `eventName` in the CloudTrail event. (ID: EVENT_NAME)
29+
* Create a function in SERVICE_FILE.
30+
* Function name: Start with `_process_`, add EVENT_NAME with snake case.
31+
* Arguments: event in dict, set_tag in bool. The default value of set_tag is False.
32+
* Return value: resource name in list
33+
* If set_tag is True, check whether 'User' tag exists.
34+
* If 'User' tag doesn't exists, set 'User' tag by using 'get_user_identity' function in 'common.py'.
35+
* Add a rule below in process_event function.
36+
37+
```python
38+
if event['eventName'] == 'EVENT_NAME':
39+
result['resource_id'] = "Call the function created from PROCESS_FUNCTION"
40+
else:
41+
message = f"Cannot process event: {event['eventName']}, eventID: f{event['eventID']}"
42+
result['error'] = message
43+
```
44+
45+
## Priority
46+
47+
High
48+
49+
## Error Handling
50+
51+
N/A
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Test Code Modification
2+
3+
## Purpose
4+
5+
This rule modifies test code.
6+
7+
## Instructions
8+
9+
* If added new file in test/services/samples, mask sensitive data.
10+
* If accountId is not "000000000000", change it to "000000000000".
11+
* If values is not "test_user" after "user/", change it to "test_user".
12+
* Change same values with sourceIPAddress to "127.0.0.1".
13+
* Change principalId to "YOUR_PRINCIPAL_ID".
14+
* Change accessKeyId to "YOUR_ACCESS_KEY_ID".
15+
* If you discover same values in other places, change them in the same way.
16+
* Create test case for the action in test/services/test_services.py file.
17+
* Create a class and a test case for the service if the class doesn't exist.
18+
* If the class exists, just create a test case in the class.
19+
20+
## Priority
21+
22+
Low
23+
24+
## Error Handling
25+
26+
N/A

0 commit comments

Comments
 (0)