|
| 1 | +Parameters: |
| 2 | + App: |
| 3 | + Type: String |
| 4 | + Description: Your application's name. |
| 5 | + Env: |
| 6 | + Type: String |
| 7 | + Description: The environment name your service, job, or workflow is being deployed to. |
| 8 | + Name: |
| 9 | + Type: String |
| 10 | + Description: The name of the service, job, or workflow being deployed. |
| 11 | + Default: python_fastapi_template |
| 12 | + # Customize your Aurora Serverless cluster by setting the default value of the following parameters. |
| 13 | + pythonFastApiTemplateclusterDBName: |
| 14 | + Type: String |
| 15 | + Description: The name of the initial database to be created in the DB cluster. |
| 16 | + Default: python_fastapi_template_db |
| 17 | + # Cannot have special characters |
| 18 | + # Naming constraints: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Limits.html#RDS_Limits.Constraints |
| 19 | + pythonFastApiTemplateclusterDBAutoPauseSeconds: |
| 20 | + Type: Number |
| 21 | + Description: The duration in seconds before the cluster pauses. |
| 22 | + Default: 1000 |
| 23 | +Mappings: |
| 24 | + pythonFastApiTemplateclusterEnvScalingConfigurationMap: |
| 25 | + prod: |
| 26 | + "DBMinCapacity": 1 # AllowedValues: [1, 2, 4, 8, 16, 32, 64, 128, 256] |
| 27 | + "DBMaxCapacity": 8 # AllowedValues: [1, 2, 4, 8, 16, 32, 64, 128, 256] |
| 28 | + All: |
| 29 | + "DBMinCapacity": 1 # AllowedValues: [1, 2, 4, 8, 16, 32, 64, 128, 256] |
| 30 | + "DBMaxCapacity": 8 # AllowedValues: [1, 2, 4, 8, 16, 32, 64, 128, 256] |
| 31 | + |
| 32 | +Resources: |
| 33 | + pythonFastApiTemplateclusterDBSubnetGroup: |
| 34 | + Type: 'AWS::RDS::DBSubnetGroup' |
| 35 | + Properties: |
| 36 | + DBSubnetGroupDescription: Group of Copilot private subnets for Aurora cluster. |
| 37 | + SubnetIds: |
| 38 | + !Split [',', { 'Fn::ImportValue': !Sub '${App}-${Env}-PrivateSubnets' }] |
| 39 | + pythonFastApiTemplateclusterSecurityGroup: |
| 40 | + Metadata: |
| 41 | + 'aws:copilot:description': 'A security group for your workload to access the DB cluster pythonFastApiTemplatecluster' |
| 42 | + Type: 'AWS::EC2::SecurityGroup' |
| 43 | + Properties: |
| 44 | + GroupDescription: !Sub 'The Security Group for ${Name} to access DB cluster pythonFastApiTemplatecluster.' |
| 45 | + VpcId: |
| 46 | + Fn::ImportValue: |
| 47 | + !Sub '${App}-${Env}-VpcId' |
| 48 | + Tags: |
| 49 | + - Key: Name |
| 50 | + Value: !Sub 'copilot-${App}-${Env}-${Name}-Aurora' |
| 51 | + pythonFastApiTemplateclusterDBClusterSecurityGroup: |
| 52 | + Metadata: |
| 53 | + 'aws:copilot:description': 'A security group for your DB cluster pythonFastApiTemplatecluster' |
| 54 | + Type: AWS::EC2::SecurityGroup |
| 55 | + Properties: |
| 56 | + GroupDescription: The Security Group for the database cluster. |
| 57 | + SecurityGroupIngress: |
| 58 | + - ToPort: 3306 |
| 59 | + FromPort: 3306 |
| 60 | + IpProtocol: tcp |
| 61 | + SourceSecurityGroupId: |
| 62 | + Fn::ImportValue: |
| 63 | + !Sub '${App}-${Env}-EnvironmentSecurityGroup' |
| 64 | + Description: Allow incoming connections from any IP address. |
| 65 | + VpcId: |
| 66 | + Fn::ImportValue: |
| 67 | + !Sub '${App}-${Env}-VpcId' |
| 68 | + Tags: |
| 69 | + - Key: Name |
| 70 | + Value: !Sub 'copilot-${App}-${Env}-${Name}-Aurora' |
| 71 | + pythonFastApiTemplateclusterAuroraSecret: |
| 72 | + Metadata: |
| 73 | + 'aws:copilot:description': 'A Secrets Manager secret to store your DB credentials' |
| 74 | + Type: AWS::SecretsManager::Secret |
| 75 | + Properties: |
| 76 | + Description: !Sub Aurora main user secret for ${AWS::StackName} |
| 77 | + GenerateSecretString: |
| 78 | + SecretStringTemplate: '{"username": "admin"}' |
| 79 | + GenerateStringKey: "password" |
| 80 | + ExcludePunctuation: true |
| 81 | + IncludeSpace: false |
| 82 | + PasswordLength: 16 |
| 83 | + pythonFastApiTemplateclusterDBClusterParameterGroup: |
| 84 | + Metadata: |
| 85 | + 'aws:copilot:description': 'A DB parameter group for engine configuration values' |
| 86 | + Type: 'AWS::RDS::DBClusterParameterGroup' |
| 87 | + Properties: |
| 88 | + Description: !Ref 'AWS::StackName' |
| 89 | + Family: 'aurora-mysql5.7' |
| 90 | + Parameters: |
| 91 | + character_set_client: 'utf8' |
| 92 | + pythonFastApiTemplateclusterDBCluster: |
| 93 | + Metadata: |
| 94 | + 'aws:copilot:description': 'The pythonFastApiTemplatecluster Aurora Serverless database cluster' |
| 95 | + Type: 'AWS::RDS::DBCluster' |
| 96 | + Properties: |
| 97 | + MasterUsername: |
| 98 | + !Join [ "", [ '{{resolve:secretsmanager:', !Ref pythonFastApiTemplateclusterAuroraSecret, ":SecretString:username}}" ]] |
| 99 | + MasterUserPassword: |
| 100 | + !Join [ "", [ '{{resolve:secretsmanager:', !Ref pythonFastApiTemplateclusterAuroraSecret, ":SecretString:password}}" ]] |
| 101 | + DatabaseName: !Ref pythonFastApiTemplateclusterDBName |
| 102 | + Engine: 'aurora-mysql' |
| 103 | + EngineVersion: '5.7.mysql_aurora.2.07.1' |
| 104 | + EngineMode: serverless |
| 105 | + DBClusterParameterGroupName: !Ref pythonFastApiTemplateclusterDBClusterParameterGroup |
| 106 | + DBSubnetGroupName: !Ref pythonFastApiTemplateclusterDBSubnetGroup |
| 107 | + VpcSecurityGroupIds: |
| 108 | + - !Ref pythonFastApiTemplateclusterDBClusterSecurityGroup |
| 109 | + ScalingConfiguration: |
| 110 | + AutoPause: true |
| 111 | + # Replace "All" below with "!Ref Env" to set different autoscaling limits per environment. |
| 112 | + MinCapacity: !FindInMap [pythonFastApiTemplateclusterEnvScalingConfigurationMap, All, DBMinCapacity] |
| 113 | + MaxCapacity: !FindInMap [pythonFastApiTemplateclusterEnvScalingConfigurationMap, All, DBMaxCapacity] |
| 114 | + SecondsUntilAutoPause: !Ref pythonFastApiTemplateclusterDBAutoPauseSeconds |
| 115 | + pythonFastApiTemplateclusterSecretAuroraClusterAttachment: |
| 116 | + Type: AWS::SecretsManager::SecretTargetAttachment |
| 117 | + Properties: |
| 118 | + SecretId: !Ref pythonFastApiTemplateclusterAuroraSecret |
| 119 | + TargetId: !Ref pythonFastApiTemplateclusterDBCluster |
| 120 | + TargetType: AWS::RDS::DBCluster |
| 121 | +Outputs: |
| 122 | + pythonFastApiTemplateclusterSecret: # injected as pythonFastApiTemplateCLUSTER_SECRET environment variable by Copilot. |
| 123 | + Description: "The JSON secret that holds the database username and password. Fields are 'host', 'port', 'dbname', 'username', 'password', 'dbClusterIdentifier' and 'engine'" |
| 124 | + Value: !Ref pythonFastApiTemplateclusterAuroraSecret |
| 125 | + Export: |
| 126 | + Name: pythonFastApiTemplateclusterSecret |
| 127 | + pythonFastApiTemplateclusterSecurityGroup: |
| 128 | + Description: "The security group to attach to the workload." |
| 129 | + Value: !Ref pythonFastApiTemplateclusterSecurityGroup |
0 commit comments