Skip to content

Commit 0d3baf6

Browse files
authored
Merge pull request #2 from sktan/cdk
Added some CDK code to deploy the proxy into an AWS environment
2 parents d05b971 + a31abe9 commit 0d3baf6

14 files changed

Lines changed: 540 additions & 3 deletions

.pre-commit-config.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.1.0 # Use the ref you want to point at
3+
rev: v4.1.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
77
- id: mixed-line-ending
88
# - id: no-commit-to-branch
99
# name: Don't commit to master
10+
- repo: https://github.com/psf/black
11+
rev: 22.3.0
12+
hooks:
13+
- id: black
14+
language_version: python3.10

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,42 @@ services:
7777
- 8080:8080
7878
```
7979

80-
### AWS Example
80+
### AWS CDK Example
8181

8282
You will be able to use the CDK template in the `cdk` directory to create a Load Balancer, a fargate container and a CodeArtifact repository (if you desire).
8383

84+
Modify the variables in app.py (or copy the `cdk/code_artifact_proxy.py` file to your codebase).
85+
86+
```
87+
root ➜ /workspaces/aws-codeartifact-proxy/cdk (cdk ✗) $ pipenv install
88+
Installing dependencies from Pipfile.lock (1a118d)...
89+
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
90+
To activate this project's virtualenv, run pipenv shell.
91+
Alternatively, run a command inside the virtualenv with pipenv run.
92+
root ➜ /workspaces/aws-codeartifact-proxy/cdk (cdk ✗) $ pipenv run cdk deploy
93+
```
94+
95+
If you'd rather use your own CDK codebase, you can use the following snippet in your `app.py` file:
96+
8497
```
85-
# Currently TODO
98+
# Replace me with where you have placed your codeartifact module
99+
from cdk.code_artifact_proxy import CodeArtifactProxy
100+
101+
proxy = CodeArtifactProxy(
102+
app,
103+
"codeartifact-proxy",
104+
# Replace the 3 lines below with your own values
105+
domain_name="mycodeartifactdomain",
106+
repository_name="internalrepo",
107+
vpc_id="vpc-1234567",
108+
env=cdk.Environment(
109+
account=os.environ["CDK_DEFAULT_ACCOUNT"],
110+
region=os.environ["CDK_DEFAULT_REGION"],
111+
),
112+
)
113+
114+
proxy.create_code_artifact()
115+
proxy.create_loadbalanced_fargate()
86116
```
87117

88118
## Testing Access

cdk/.gitignore

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

cdk/Pipfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
aws-cdk-lib = "*"
8+
constructs = "*"
9+
10+
[dev-packages]
11+
black = "*"
12+
pytest = "*"
13+
14+
[requires]
15+
python_version = "3.10"

cdk/Pipfile.lock

Lines changed: 223 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cdk/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# AWS Code Commit Proxy CDK Stack
3+
4+
This deploys a CDK stack with the following resources:
5+
6+
1. AWS Application Load Balancer
7+
2. Fargate Container
8+
3. IAM Role for Fargate access to Code Artifact
9+
4. (Optional) Code Artifact Repository
10+
5. (Optional) VPC

cdk/app.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
import os
3+
4+
import aws_cdk as cdk
5+
6+
from cdk.code_artifact_proxy import CodeArtifactProxy
7+
8+
app = cdk.App()
9+
10+
cdk_env = cdk.Environment(
11+
account=os.environ["CDK_DEFAULT_ACCOUNT"],
12+
region=os.environ["CDK_DEFAULT_REGION"],
13+
)
14+
15+
proxy = CodeArtifactProxy(
16+
app,
17+
"codeartifact-proxy",
18+
# Replace the 3 lines below with your own values
19+
domain_name="mycodeartifactdomain",
20+
repository_name="internalrepo",
21+
vpc_id="vpc-1234567",
22+
env=cdk_env,
23+
)
24+
25+
# This is actually optional if you do not already have a codeartifact repository
26+
proxy.create_code_artifact()
27+
proxy.create_loadbalanced_fargate()
28+
29+
app.synth()

cdk/cdk.context.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

cdk/cdk.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
23+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
24+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
25+
"@aws-cdk/aws-iam:minimizePolicies": true,
26+
"@aws-cdk/core:target-partitions": [
27+
"aws",
28+
"aws-cn"
29+
]
30+
}
31+
}

cdk/cdk/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)