Skip to content

Commit

Permalink
Merge pull request #436 from ericzbeard/main
Browse files Browse the repository at this point in the history
Generating JSON
  • Loading branch information
ericzbeard authored May 31, 2024
2 parents 20d9faa + 8f577cd commit da038b3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Config/Config.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
"ZipFile": "var aws = require('aws-sdk');\nvar config = new aws.ConfigService();\nvar ec2 = new aws.EC2();\nexports.handler = function(event, context) {\n var compliance = evaluateCompliance(event, function(compliance, event) {\n var configurationItem = JSON.parse(event.invokingEvent).configurationItem;\n var putEvaluationsRequest = {\n Evaluations: [{\n ComplianceResourceType: configurationItem.resourceType,\n ComplianceResourceId: configurationItem.resourceId,\n ComplianceType: compliance,\n OrderingTimestamp: configurationItem.configurationItemCaptureTime\n }],\n ResultToken: event.resultToken\n };\n config.putEvaluations(putEvaluationsRequest, function(err, data) {\n if (err) context.fail(err);\n else context.succeed(data);\n });\n });\n};\nfunction evaluateCompliance(event, doReturn) {\n var configurationItem = JSON.parse(event.invokingEvent).configurationItem;\n var status = configurationItem.configurationItemStatus;\n if (configurationItem.resourceType !== 'AWS::EC2::Volume' || event.eventLeftScope || (status !== 'OK' && status !== 'ResourceDiscovered'))\n doReturn('NOT_APPLICABLE', event);\n else ec2.describeVolumeAttribute({VolumeId: configurationItem.resourceId, Attribute: 'autoEnableIO'}, function(err, data) {\n if (err) context.fail(err);\n else if (data.AutoEnableIO.Value) doReturn('COMPLIANT', event);\n else doReturn('NON_COMPLIANT', event);\n });\n}\n"
},
"Handler": "index.handler",
"Runtime": "nodejs16.x",
"Runtime": "nodejs20.x",
"Timeout": "30",
"Role": {
"Fn::GetAtt": [
Expand Down
21 changes: 20 additions & 1 deletion RDS/RDS_MySQL_With_Read_Replica.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,21 @@
},
"Condition": "IsEC2VPC"
},
"DBCredential": {
"Type": "AWS::SecretsManager::Secret",
"Properties": {
"GenerateSecretString": {
"PasswordLength": 16,
"ExcludeCharacters": "\"@/\\",
"RequireEachIncludedType": true
}
}
},
"MainDB": {
"DeletionPolicy": "Snapshot",
"UpdateReplacePolicy": "Snapshot",
"Type": "AWS::RDS::DBInstance",
"DependsOn": "DBCredential",
"Properties": {
"DBName": {
"Ref": "DBName"
Expand All @@ -132,7 +143,9 @@
"MasterUsername": {
"Ref": "DBUser"
},
"MasterUserPassword": "{{resolve:secretsmanager:my-db-password}}",
"MasterUserPassword": {
"Fn::Sub": "{{resolve:secretsmanager:${DBCredential}}}"
},
"MultiAZ": {
"Ref": "MultiAZ"
},
Expand Down Expand Up @@ -194,6 +207,12 @@
}
},
"Outputs": {
"DBCredentialSecretNameArn": {
"Description": "Name of the secret containing the database credential",
"Value": {
"Ref": "DBCredential"
}
},
"EC2Platform": {
"Description": "Platform in which this stack is deployed",
"Value": {
Expand Down
15 changes: 14 additions & 1 deletion RDS/RDS_PIOPS.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@
}
},
"Resources": {
"DBCredential": {
"Type": "AWS::SecretsManager::Secret",
"Properties": {
"GenerateSecretString": {
"PasswordLength": 16,
"ExcludeCharacters": "\"@/\\",
"RequireEachIncludedType": true
}
}
},
"myDB": {
"Type": "AWS::RDS::DBInstance",
"DependsOn": "DBCredential",
"Properties": {
"AllocatedStorage": "100",
"DBInstanceClass": "db.t3.small",
Expand All @@ -27,7 +38,9 @@
"MasterUsername": {
"Ref": "DBUser"
},
"MasterUserPassword": "{{resolve:secretsmanager:my-db-password}}",
"MasterUserPassword": {
"Fn::Sub": "{{resolve:secretsmanager:${DBCredential}}}"
},
"PubliclyAccessible": false,
"StorageEncrypted": true
}
Expand Down
5 changes: 2 additions & 3 deletions RDS/RDS_with_DBParameterGroup.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@
"MyRDSParamGroup": {
"Type": "AWS::RDS::DBParameterGroup",
"Properties": {
"Family": "MySQL5.6",
"Family": "MySQL8.0",
"Description": "CloudFormation Sample Database Parameter Group",
"Parameters": {
"autocommit": "1",
"general_log": "1",
"old_passwords": "0"
"general_log": "1"
}
}
}
Expand Down

0 comments on commit da038b3

Please sign in to comment.