Skip to content

Commit bd973c7

Browse files
committed
Add Integ test for init process
1 parent 17a55e8 commit bd973c7

File tree

17 files changed

+361
-0
lines changed

17 files changed

+361
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[INPUT]
2+
Name dummy
3+
Tag dummy.data
4+
Dummy {"data":"100 0.5 true This is Demo"}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[FILTER]
2+
Name parser
3+
Match dummy.*
4+
Key_Name data
5+
Parser dummy_test
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[PARSER]
2+
Name dummy_test
3+
Format regex
4+
Regex ^(?<INT>[^ ]+) (?<FLOAT>[^ ]+) (?<BOOL>[^ ]+) (?<STRING>.+)$
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[OUTPUT]
2+
Name s3
3+
Match dummy.*
4+
bucket your-result-bucket
5+
region ${AWS_REGION}
6+
total_file_size 1M
7+
upload_timeout 1m
8+
use_put_object On
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.swp
2+
package-lock.json
3+
__pycache__
4+
.pytest_cache
5+
.venv
6+
*.egg-info
7+
8+
# CDK asset staging directory
9+
.cdk.staging
10+
cdk.out
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
# Welcome to your CDK Python project!
3+
4+
**This CDK project can help you deploying resources needed for Integ test automated.**
5+
6+
The `cdk.json` file tells the CDK Toolkit how to execute your app.
7+
8+
This project is set up like a standard Python project. The initialization
9+
process also creates a virtualenv within this project, stored under the `.venv`
10+
directory. To create the virtualenv it assumes that there is a `python3`
11+
(or `python` for Windows) executable in your path with access to the `venv`
12+
package. If for any reason the automatic creation of the virtualenv fails,
13+
you can create the virtualenv manually.
14+
15+
To manually create a virtualenv on MacOS and Linux:
16+
17+
```
18+
$ python3 -m venv .venv
19+
```
20+
21+
After the init process completes and the virtualenv is created, you can use the following
22+
step to activate your virtualenv.
23+
24+
```
25+
$ source .venv/bin/activate
26+
```
27+
28+
If you are a Windows platform, you would activate the virtualenv like this:
29+
30+
```
31+
% .venv\Scripts\activate.bat
32+
```
33+
34+
Once the virtualenv is activated, you can install the required dependencies.
35+
36+
```
37+
$ pip install -r requirements.txt
38+
```
39+
40+
At this point you can now synthesize the CloudFormation template for this code.
41+
42+
```
43+
$ cdk synth
44+
```
45+
46+
To add additional dependencies, for example other CDK libraries, just add
47+
them to your `setup.py` file and rerun the `pip install -r requirements.txt`
48+
command.
49+
50+
## Useful commands
51+
52+
* `cdk ls` list all stacks in the app
53+
* `cdk synth` emits the synthesized CloudFormation template
54+
* `cdk deploy` deploy this stack to your default AWS account/region
55+
* `cdk diff` compare deployed stack with current state
56+
* `cdk docs` open CDK documentation
57+
58+
Enjoy!

integ/test_init/integ_test/app.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
import os
3+
4+
import aws_cdk as cdk
5+
6+
from integ_test.integ_test_stack import IntegTestStack
7+
8+
9+
app = cdk.App()
10+
IntegTestStack(app, "IntegTestStack",
11+
# If you don't specify 'env', this stack will be environment-agnostic.
12+
# Account/Region-dependent features and context lookups will not work,
13+
# but a single synthesized template can be deployed anywhere.
14+
15+
# Uncomment the next line to specialize this stack for the AWS Account
16+
# and Region that are implied by the current CLI configuration.
17+
18+
#env=cdk.Environment(account=os.getenv('CDK_DEFAULT_ACCOUNT'), region=os.getenv('CDK_DEFAULT_REGION')),
19+
20+
# Uncomment the next line if you know exactly what Account and Region you
21+
# want to deploy the stack to. */
22+
23+
#env=cdk.Environment(account='123456789012', region='us-east-1'),
24+
25+
# For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
26+
)
27+
28+
app.synth()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"app": "python3 app.py",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"requirements*.txt",
11+
"source.bat",
12+
"**/__init__.py",
13+
"python/__pycache__",
14+
"tests"
15+
]
16+
},
17+
"context": {
18+
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
19+
"@aws-cdk/core:stackRelativeExports": true,
20+
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
21+
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
22+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
23+
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
24+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
25+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
26+
"@aws-cdk/core:checkSecretUsage": true,
27+
"@aws-cdk/aws-iam:minimizePolicies": true,
28+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
29+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
30+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
31+
"@aws-cdk/core:target-partitions": [
32+
"aws",
33+
"aws-cn"
34+
]
35+
}
36+
}

integ/test_init/integ_test/integ_test/__init__.py

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from aws_cdk import (
2+
Stack,
3+
aws_autoscaling as autoscaling,
4+
aws_ec2 as ec2,
5+
aws_ecs as ecs,
6+
aws_iam as iam,
7+
)
8+
from constructs import Construct
9+
10+
# change your ARNs here
11+
arn1 = "arn:aws:s3:::yourBucket/dummy-input.conf"
12+
arn2 = "arn:aws:s3:::yourBucket/dummy-filter.conf"
13+
arn3 = "arn:aws:s3:::yourBucket/dummy-parser.conf"
14+
arn4 = "arn:aws:s3:::yourBucket/dummy-s3-output.conf"
15+
16+
class IntegTestStack(Stack):
17+
18+
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
19+
super().__init__(scope, construct_id, **kwargs)
20+
21+
vpc = ec2.Vpc(self, "VPC")
22+
23+
cluster = ecs.Cluster(self, "Cluster", vpc=vpc)
24+
25+
auto_scaling_group = autoscaling.AutoScalingGroup(self, "ASG",
26+
vpc=vpc,
27+
instance_type=ec2.InstanceType("t2.micro"),
28+
machine_image=ecs.EcsOptimizedImage.amazon_linux2(),
29+
)
30+
31+
capacity_provider = ecs.AsgCapacityProvider(self,
32+
"AsgCapacityProvider",
33+
auto_scaling_group=auto_scaling_group
34+
)
35+
36+
cluster.add_asg_capacity_provider(capacity_provider)
37+
38+
task_definition = ecs.Ec2TaskDefinition(self, "TaskDef")
39+
40+
task_definition.add_container("log_router",
41+
image=ecs.ContainerImage.from_registry("public.ecr.aws/aws-observability/aws-for-fluent-bit:init-latest"),
42+
memory_reservation_mib=50,
43+
logging=ecs.LogDrivers.aws_logs(
44+
stream_prefix="Firelens-log",
45+
),
46+
environment={
47+
"aws_fluent_bit_init_s3_1": arn1,
48+
"aws_fluent_bit_init_s3_2": arn2,
49+
"aws_fluent_bit_init_s3_3": arn3,
50+
"aws_fluent_bit_init_s3_4": arn4,
51+
},
52+
)
53+
54+
task_definition.task_role.add_managed_policy(
55+
iam.ManagedPolicy.from_aws_managed_policy_name("AmazonS3FullAccess")
56+
)
57+
58+
task_definition.task_role.add_managed_policy(
59+
iam.ManagedPolicy.from_aws_managed_policy_name("AmazonSSMFullAccess")
60+
)
61+
62+
task_definition.task_role.add_managed_policy(
63+
iam.ManagedPolicy.from_aws_managed_policy_name("CloudWatchFullAccess")
64+
)
65+
66+
ecs_service = ecs.Ec2Service(self, "Service",
67+
cluster=cluster,
68+
task_definition=task_definition,
69+
enable_execute_command=True
70+
)

0 commit comments

Comments
 (0)