Skip to content

Commit

Permalink
placeholder components for aws batch iaac
Browse files Browse the repository at this point in the history
  • Loading branch information
luiztauffer committed Oct 26, 2023
1 parent 0a695f9 commit 3ffc09e
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/protocaas/iaac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Useful commands

* `cdk ls` list all stacks in the app
* `cdk synth` synthesizes CloudFormation template
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk docs` open CDK documentation


## Refs

- https://constructs.dev/packages/@aws-cdk/aws-batch-alpha/v/2.95.1-alpha.0?lang=python

22 changes: 22 additions & 0 deletions python/protocaas/iaac/aws_batch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*.swp
package-lock.json
.pytest_cache
*.egg-info

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# CDK Context & Staging files
.cdk.staging/
cdk.out/
65 changes: 65 additions & 0 deletions python/protocaas/iaac/aws_batch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

# Welcome to your CDK Python project!

You should explore the contents of this project. It demonstrates a CDK app with an instance of a stack (`aws_batch_stack`)
which contains an Amazon SQS queue that is subscribed to an Amazon SNS topic.

The `cdk.json` file tells the CDK Toolkit how to execute your app.

This project is set up like a standard Python project. The initialization process also creates
a virtualenv within this project, stored under the .venv directory. To create the virtualenv
it assumes that there is a `python3` executable in your path with access to the `venv` package.
If for any reason the automatic creation of the virtualenv fails, you can create the virtualenv
manually once the init process completes.

To manually create a virtualenv on MacOS and Linux:

```
$ python3 -m venv .venv
```

After the init process completes and the virtualenv is created, you can use the following
step to activate your virtualenv.

```
$ source .venv/bin/activate
```

If you are a Windows platform, you would activate the virtualenv like this:

```
% .venv\Scripts\activate.bat
```

Once the virtualenv is activated, you can install the required dependencies.

```
$ pip install -r requirements.txt
```

At this point you can now synthesize the CloudFormation template for this code.

```
$ cdk synth
```

You can now begin exploring the source code, contained in the hello directory.
There is also a very trivial test included that can be run like this:

```
$ pytest
```

To add additional dependencies, for example other CDK libraries, just add to
your requirements.txt file and rerun the `pip install -r requirements.txt`
command.

## Useful commands

* `cdk ls` list all stacks in the app
* `cdk synth` emits the synthesized CloudFormation template
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk docs` open CDK documentation

Enjoy!
11 changes: 11 additions & 0 deletions python/protocaas/iaac/aws_batch/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3

import aws_cdk as cdk

from aws_batch.aws_batch_stack import AwsBatchStack


app = cdk.App()
AwsBatchStack(app, "aws-batch")

app.synth()
Empty file.
43 changes: 43 additions & 0 deletions python/protocaas/iaac/aws_batch/aws_batch/aws_batch_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from constructs import Construct
from aws_cdk import (
Stack,
aws_iam as iam,
aws_ec2 as ec2,
aws_batch as batch,
)


class AwsBatchStack(Stack):

def __init__(self, scope: Construct, stack_id: str, **kwargs) -> None:
super().__init__(scope, stack_id, **kwargs)

# VPC
vpc = ec2.Vpc(
scope=self,
id=f"{stack_id}-vpc",
max_azs=3,
)

# Compute environment
compute_env = batch.FargateComputeEnvironment(
scope=self,
id=f"{stack_id}-compute-env",
spot=True,
maxv_cpus=1,
vpc=vpc,
)

# Job queue
job_queue = batch.JobQueue(
scope=self,
id=f"{stack_id}-job-queue",
job_queue_name=f"{stack_id}-job-queue",
priority=1,
compute_environments=[
batch.JobQueueComputeEnvironment(
compute_environment=compute_env,
order=1,
)
],
)
58 changes: 58 additions & 0 deletions python/protocaas/iaac/aws_batch/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"app": "python3 app.py",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"requirements*.txt",
"source.bat",
"**/__init__.py",
"python/__pycache__",
"tests"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk/aws-kms:aliasNameRef": true,
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true
}
}
1 change: 1 addition & 0 deletions python/protocaas/iaac/aws_batch/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==6.2.5
2 changes: 2 additions & 0 deletions python/protocaas/iaac/aws_batch/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aws-cdk-lib==2.93.0
constructs>=10.0.0,<11.0.0
13 changes: 13 additions & 0 deletions python/protocaas/iaac/aws_batch/source.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off

rem The sole purpose of this script is to make the command
rem
rem source .venv/bin/activate
rem
rem (which activates a Python virtualenv on Linux or Mac OS X) work on Windows.
rem On Windows, this command just runs this batch file (the argument is ignored).
rem
rem Now we don't need to document a Windows command for activating a virtualenv.

echo Executing .venv\Scripts\activate.bat for you
.venv\Scripts\activate.bat
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions python/protocaas/iaac/aws_batch/tests/unit/test_aws_batch_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# import aws_cdk as core
# import aws_cdk.assertions as assertions
# from aws_batch.aws_batch_stack import AwsBatchStack


# def test_sqs_queue_created():
# app = core.App()
# stack = AwsBatchStack(app, "aws-batch")
# template = assertions.Template.from_stack(stack)

# template.has_resource_properties("AWS::SQS::Queue", {
# "VisibilityTimeout": 300
# })


# def test_sns_topic_created():
# app = core.App()
# stack = AwsBatchStack(app, "aws-batch")
# template = assertions.Template.from_stack(stack)

# template.resource_count_is("AWS::SNS::Topic", 1)

0 comments on commit 3ffc09e

Please sign in to comment.