forked from AWSCookbook/Databases
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5371f36
commit 3428057
Showing
553 changed files
with
80,854 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Desktop (please complete the following information):** | ||
- OS: [e.g. iOS] | ||
- Browser [e.g. chrome, safari] | ||
- Version [e.g. 22] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
name: Recipe request | ||
about: Suggest a recipe for this Chapter | ||
title: '' | ||
labels: enhancement | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Is your recipe request related to a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe what you'd like to learn** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Recipe Title | ||
## Preparation | ||
### Step Text | ||
code goes here | ||
|
||
## Steps | ||
### Step Text | ||
code goes here | ||
|
||
### Step Text | ||
code goes here | ||
|
||
|
||
## Clean up | ||
### Step Text | ||
code goes here |
10 changes: 10 additions & 0 deletions
10
401-Creating-an-Aurora-Serverless-DB/cdk-AWS-Cookbook-101/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.swp | ||
package-lock.json | ||
__pycache__ | ||
.pytest_cache | ||
.env | ||
*.egg-info | ||
|
||
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out |
58 changes: 58 additions & 0 deletions
58
401-Creating-an-Aurora-Serverless-DB/cdk-AWS-Cookbook-101/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
# Welcome to your CDK Python project! | ||
|
||
This is a blank project for Python development with CDK. | ||
|
||
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` | ||
(or `python` for Windows) 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. | ||
|
||
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 | ||
``` | ||
|
||
To add additional dependencies, for example other CDK libraries, just add | ||
them to your `setup.py` 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
11
401-Creating-an-Aurora-Serverless-DB/cdk-AWS-Cookbook-101/app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from aws_cdk import core | ||
|
||
from cdk_aws_cookbook_101.cdk_aws_cookbook_101_stack import CdkAwsCookbook101Stack | ||
|
||
|
||
app = core.App() | ||
CdkAwsCookbook101Stack(app, "cdk-aws-cookbook-101") | ||
|
||
app.synth() |
11 changes: 11 additions & 0 deletions
11
401-Creating-an-Aurora-Serverless-DB/cdk-AWS-Cookbook-101/cdk.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"app": "python3 app.py", | ||
"context": { | ||
"@aws-cdk/core:enableStackNameDuplicates": "true", | ||
"aws-cdk:enableDiffNoFail": "true", | ||
"@aws-cdk/core:stackRelativeExports": "true", | ||
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true, | ||
"@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true, | ||
"@aws-cdk/aws-kms:defaultKeyPolicies": true | ||
} | ||
} |
Empty file.
117 changes: 117 additions & 0 deletions
117
...ora-Serverless-DB/cdk-AWS-Cookbook-101/cdk_aws_cookbook_101/cdk_aws_cookbook_101_stack.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from aws_cdk import ( | ||
aws_ec2 as ec2, | ||
core, | ||
aws_iam as iam, | ||
) | ||
|
||
|
||
class CdkAwsCookbook101Stack(core.Stack): | ||
|
||
def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None: | ||
super().__init__(scope, construct_id, **kwargs) | ||
|
||
isolated_subnets = ec2.SubnetConfiguration( | ||
name="ISOLATED", | ||
subnet_type=ec2.SubnetType.ISOLATED, | ||
cidr_mask=24 | ||
) | ||
|
||
# create VPC | ||
vpc = ec2.Vpc( | ||
self, | ||
'AWS-Cookbook-VPC-101', | ||
cidr='10.10.0.0/23', | ||
subnet_configuration=[isolated_subnets] | ||
) | ||
|
||
vpc.add_gateway_endpoint( | ||
's3GateWayEndPoint', | ||
service=ec2.GatewayVpcEndpointAwsService('s3'), | ||
subnets=[ec2.SubnetSelection(subnet_type=ec2.SubnetType.ISOLATED)], | ||
) | ||
|
||
# -------- Begin EC2 Helper --------- | ||
vpc.add_interface_endpoint( | ||
'VPCSSMInterfaceEndpoint', | ||
service=ec2.InterfaceVpcEndpointAwsService('ssm'), # Find names with - aws ec2 describe-vpc-endpoint-services | jq '.ServiceNames' | ||
private_dns_enabled=True, | ||
subnets=ec2.SubnetSelection( | ||
one_per_az=False, | ||
subnet_type=ec2.SubnetType.ISOLATED | ||
), | ||
) | ||
|
||
vpc.add_interface_endpoint( | ||
'VPCEC2MessagesInterfaceEndpoint', | ||
service=ec2.InterfaceVpcEndpointAwsService('ec2messages'), # Find names with - aws ec2 describe-vpc-endpoint-services | jq '.ServiceNames' | ||
private_dns_enabled=True, | ||
subnets=ec2.SubnetSelection( | ||
one_per_az=False, | ||
subnet_type=ec2.SubnetType.ISOLATED | ||
), | ||
) | ||
|
||
vpc.add_interface_endpoint( | ||
'VPCSSMMessagesInterfaceEndpoint', | ||
service=ec2.InterfaceVpcEndpointAwsService('ssmmessages'), # Find names with - aws ec2 describe-vpc-endpoint-services | jq '.ServiceNames' | ||
private_dns_enabled=True, | ||
subnets=ec2.SubnetSelection( | ||
one_per_az=False, | ||
subnet_type=ec2.SubnetType.ISOLATED | ||
), | ||
) | ||
|
||
ami = ec2.MachineImage.latest_amazon_linux( | ||
generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2, | ||
edition=ec2.AmazonLinuxEdition.STANDARD, | ||
virtualization=ec2.AmazonLinuxVirt.HVM, | ||
storage=ec2.AmazonLinuxStorage.GENERAL_PURPOSE | ||
) | ||
|
||
iam_role = iam.Role(self, "InstanceSSM", assumed_by=iam.ServicePrincipal("ec2.amazonaws.com")) | ||
|
||
iam_role.add_managed_policy(iam.ManagedPolicy.from_aws_managed_policy_name("service-role/AmazonEC2RoleforSSM")) | ||
|
||
instance = ec2.Instance( | ||
self, | ||
"Instance", | ||
instance_type=ec2.InstanceType("t3.nano"), | ||
machine_image=ami, | ||
role=iam_role, | ||
vpc=vpc, | ||
) | ||
|
||
core.CfnOutput( | ||
self, | ||
'InstanceID', | ||
value=instance.instance_id | ||
) | ||
# -------- End EC2 Helper --------- | ||
|
||
# outputs | ||
|
||
core.CfnOutput( | ||
self, | ||
'VPCId', | ||
value=vpc.vpc_id | ||
) | ||
|
||
isolated_subnets = vpc.select_subnets(subnet_type=ec2.SubnetType.ISOLATED) | ||
|
||
core.CfnOutput( | ||
self, | ||
'Subnet1ID', | ||
value=isolated_subnets.subnet_ids[0] | ||
) | ||
|
||
core.CfnOutput( | ||
self, | ||
'Subnet2ID', | ||
value=isolated_subnets.subnet_ids[1] | ||
) | ||
|
||
core.CfnOutput( | ||
self, | ||
'InstanceSG', | ||
value=instance.connections.security_groups[0].security_group_id | ||
) |
33 changes: 33 additions & 0 deletions
33
401-Creating-an-Aurora-Serverless-DB/cdk-AWS-Cookbook-101/helper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import boto3 | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description="Generate commands to set and unset environment variables") | ||
parser.add_argument('--unset', action='store_true', help="Generate commands to unset environment variables by setting this flag") | ||
|
||
args = parser.parse_args() | ||
|
||
os.environ['AWS_DEFAULT_REGION'] = os.environ.get('AWS_REGION') | ||
|
||
cfn = boto3.client('cloudformation') | ||
stackname = os.path.basename(os.getcwd()).lower() | ||
response = cfn.describe_stacks(StackName=stackname) | ||
unsets = [] | ||
sets = [] | ||
|
||
outputs = response["Stacks"][0]["Outputs"] | ||
print("Copy and paste the commands below into your terminal") | ||
print("") | ||
for output in outputs: | ||
if ', ' in output["OutputValue"]: | ||
sets.append(output["OutputKey"] + "='" + ', '.join('"{}"'.format(word) for word in output["OutputValue"].split(", ")) + "'") | ||
else: | ||
sets.append(output["OutputKey"] + "='" + output["OutputValue"] + "'") | ||
unsets.append("unset " + output["OutputKey"]) | ||
|
||
if (args.unset): | ||
print('\n'.join(map(str, unsets))) | ||
else: | ||
print('\n'.join(map(str, sets))) | ||
|
||
print("") |
58 changes: 58 additions & 0 deletions
58
401-Creating-an-Aurora-Serverless-DB/cdk-AWS-Cookbook-101/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-e . | ||
boto3 | ||
botocore | ||
jsii | ||
attr | ||
attrs | ||
cattrs | ||
constructs | ||
typing_extensions | ||
jmespath | ||
publication | ||
python-dateutil | ||
s3transfer | ||
six | ||
typing-extensions | ||
urllib3 | ||
aws_cdk.core | ||
aws-cdk.assets | ||
aws-cdk.aws-apigateway | ||
aws-cdk.aws-apigatewayv2 | ||
aws-cdk.aws-applicationautoscaling | ||
aws-cdk.aws-autoscaling | ||
aws-cdk.aws-autoscaling-common | ||
aws-cdk.aws-autoscaling-hooktargets | ||
aws-cdk.aws-certificatemanager | ||
aws-cdk.aws-cloudformation | ||
aws-cdk.aws-cloudfront | ||
aws-cdk.aws-cloudwatch | ||
aws-cdk.aws-codeguruprofiler | ||
aws-cdk.aws-cognito | ||
aws-cdk.aws-ecr | ||
aws-cdk.aws-efs | ||
aws-cdk.aws-elasticloadbalancing | ||
aws-cdk.aws-elasticloadbalancingv2 | ||
aws-cdk.aws-events | ||
aws-cdk.aws-iam | ||
aws-cdk.aws-kms | ||
aws-cdk.aws-lambda | ||
aws-cdk.aws-logs | ||
aws-cdk.aws-route53 | ||
aws-cdk.aws-route53-targets | ||
aws-cdk.aws-s3 | ||
aws-cdk.aws-s3-assets | ||
aws-cdk.aws-sam | ||
aws-cdk.aws-secretsmanager | ||
aws-cdk.aws-servicediscovery | ||
aws-cdk.aws-sns | ||
aws-cdk.aws-sns-subscriptions | ||
aws-cdk.aws-sqs | ||
aws-cdk.aws-ssm | ||
aws-cdk.cloud-assembly-schema | ||
aws-cdk.custom-resources | ||
aws-cdk.cx-api | ||
aws-cdk.region-info | ||
aws_cdk.aws_ec2 | ||
aws_cdk.aws_ecs | ||
aws_cdk.aws_ecr_assets | ||
aws_cdk.aws_elasticloadbalancingv2 |
Oops, something went wrong.