Skip to content

dms certficate issue

0

ssl_mode="verify-ca", certificate_arn=

dms task needs ssl to be used i am using above in cdk code

i have downlaoded its pem but dont want to commit in cdk repo physically so want to upload it in ssm/secrets

RDS CA certificate bundle - region-specific

def get_rds_ca_bundle(): """Download region-specific RDS CA certificate bundle if not present""" # Get current region from Lambda environment region = os.environ.get('AWS_REGION', 'us-east-1')

bundle_path = f'/tmp/rds-ca-{region}.pem'
bundle_url = f'https://truststore.pki.rds.amazonaws.com/{region}/{region}-bundle.pem'

if not os.path.exists(bundle_path):
    try:
        print(f"Downloading RDS CA bundle for {region} from {bundle_url}")
        urllib.request.urlretrieve(bundle_url, bundle_path)
        print(f"RDS CA bundle downloaded to {bundle_path}")
    except Exception as e:
        print(f"Error downloading region-specific bundle: {e}")
        # Try global bundle as fallback
        try:
            global_url = 'https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem'
            print(f"Trying global bundle from {global_url}")
            urllib.request.urlretrieve(global_url, bundle_path)
            print(f"Global RDS CA bundle downloaded to {bundle_path}")
        except Exception as e2:
            print(f"Error downloading global bundle: {e2}")
            return None

return bundle_path

will this lambda work and if gets stored in secerts/ssm how to use in dms task

1 Answer
0

To use SSL with AWS Database Migration Service (DMS), you need to provide a certificate to establish a secure connection. Your approach of downloading the RDS CA certificate bundle and storing it in SSM or Secrets Manager is a good practice to avoid committing certificates to your code repository.

Your Lambda function for downloading the region-specific RDS CA certificate bundle looks correct. It attempts to download the region-specific bundle first, and if that fails, it falls back to the global bundle.

After downloading the certificate, you'll need to import it into AWS DMS using the aws dms import-certificate command. This can be done within your Lambda function after downloading the certificate:

import boto3

# After downloading the certificate
with open(bundle_path, 'r') as cert_file:
cert_content = cert_file.read()

# Import certificate to DMS
dms_client = boto3.client('dms')
response = dms_client.import-certificate(
CertificateIdentifier='rds-ca-cert',
CertificatePem=cert_content
)

# Get the certificate ARN
certificate_arn = response['Certificate']['CertificateArn']

# Store the ARN in SSM Parameter Store or Secrets Manager
ssm_client = boto3.client('ssm')
ssm_client.put_parameter(
Name='/dms/certificate/arn',
Value=certificate_arn,
Type='String',
Overwrite=True
)

Then in your CDK code, you can retrieve the certificate ARN from SSM:

// In your CDK code
const certificateArn = ssm.StringParameter.valueForStringParameter(
this, '/dms/certificate/arn'
);

// Use the certificate ARN in your DMS task
const dmsTask = new dms.CfnReplicationTask(this, 'DmsTask', {
// other properties
replicationTaskSettings: JSON.stringify({
// other settings
TargetMetadata: {
SslMode: 'verify-full',
CertificateArn: certificateArn
}
})
});

When configuring your DMS endpoint, you would reference this certificate ARN and set the SSL mode to "verify-full" to ensure secure connections. This approach allows you to use SSL with your DMS task without committing the certificate file to your repository.
Sources
Using Amazon DocumentDB as a target for AWS Database Migration Service - AWS Database Migration Service
Using SSL with AWS Database Migration Service - AWS Database Migration Service

answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.