Add parameter

Open NorthwindCdk.sln in Visual Studio.

Open NorthwindCdkStack.cs.

Add the following changes at the end of NorthwindCdkStack constructor. The following code creates new parameter in AWS Systems Manager Parameter Store named /Northwind/ConnectionStrings/NorthwindPostgreDatabase and adds full connection string to the Amazon Aurora PostgreSQL database as it’s value.

namespace NorthwindCdk
{
    public class NorthwindCdkStack : Stack
    {
        internal NorthwindCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            .........

            // Aurora PostgreSQL connection string in Systems Manager Parameter Store

            new StringParameter(this, "NorthwindPostgreSQLDatabaseConnectionString", new StringParameterProps
            {
                ParameterName = "/Northwind/ConnectionStrings/NorthwindPostgreDatabase",
                Type = ParameterType.STRING,
                Description = "PostgreSQL connection string",
                StringValue = string.Format("Server={0};Database=NorthwindTraders;Username=adminuser;Password=Admin12345?", postgreSql.ClusterEndpoint.Hostname)
            });
        }
    }
}

Save changes and compile the project.

Run cdk diff to take a look at the changes that are going to be deployed.

cdk diff

The output should look like this:

Stack NorthwindCdkStack
Resources
[+] AWS::SSM::Parameter NorthwindPostgreSQLDatabaseConnectionString NorthwindPostgreSQLDatabaseConnectionString2F8E55B7

Now it’s time to deploy the project using cdk deploy command.

cdk deploy

The output should look like the following:

NorthwindCdkStack: deploying...
NorthwindCdkStack: creating CloudFormation changeset...
 0/2 | 9:39:03 AM | CREATE_IN_PROGRESS   | AWS::SSM::Parameter                   | NorthwindPostgreSQLDatabaseConnectionString (NorthwindPostgreSQLDatabaseConnectionString2F8E55B7)
 0/2 | 9:39:05 AM | CREATE_IN_PROGRESS   | AWS::SSM::Parameter                   | NorthwindPostgreSQLDatabaseConnectionString (NorthwindPostgreSQLDatabaseConnectionString2F8E55B7) Resource creation Initiated
 1/2 | 9:39:05 AM | CREATE_COMPLETE      | AWS::SSM::Parameter                   | NorthwindPostgreSQLDatabaseConnectionString (NorthwindPostgreSQLDatabaseConnectionString2F8E55B7)
 1/2 | 9:39:07 AM | UPDATE_COMPLETE_CLEA | AWS::CloudFormation::Stack            | NorthwindCdkStack
 2/2 | 9:39:08 AM | UPDATE_COMPLETE      | AWS::CloudFormation::Stack            | NorthwindCdkStack

 ✅  NorthwindCdkStack

Outputs:
NorthwindCdkStack.SQLServerEndpointAddress = northwind-sqlserver.cyhlwzws5aoz.eu-west-1.rds.amazonaws.com
NorthwindCdkStack.PostgreSQLEndpointAddress = northwind-postgresql.cluster-cyhlwzws5aoz.eu-west-1.rds.amazonaws.com

Stack ARN:
arn:aws:cloudformation:eu-west-1:404486542784:stack/NorthwindCdkStack/f78fb1c0-8ed1-11ea-8a83-0a0af0d573f8