Skip to main content

xregion-ssm-parameter-reader

Project description

Cross-region cross-account SSM parameter reader construct for AWS CDK

Easy-to-use CDK construct for reading SSM parameters in a cross-account cross-region fashion, overcoming the limits of the native SSM parameter.

Introduction

This construct has been created to be able to share pieces of information across regions (and accounts) in deployment pipelines but it can be used also outside of the CI/CD context.

Cross-region example

This strategy is particularly useful in case of a deployment pipeline where you want to share the same parameter across regions within the same account.

As part of a stack deployed in region-1, create the parameter as usual:

new StringParameter(this, 'param', {
    parameterName: '/param/name'
    stringValue: 'param value',
});

When in region-2, use the following to read the parameter value:

const paramValue = new SSMParameterReader(this, 'SSMParameterReader', {
    parameterName: '/param/name',
    region: 'region-1',
}).retrieveParameterValue();

Cross-account example

This strategy is useful still in a deployment pipeline but to share a parameter across regions and accounts. For example, let's assume we want to share the same transit gateway across accounts and regions. The pipeline can be deployed in a CICD account, separated from the usual target accounts (i.e. dev, test and prod).

In this case you would share the resource using Resource Access Manager (out of scope for this example) and you will create two parameters in region-1 and in the CICD account, to share the transit gateway ID and the shared resource ARN:

const principals = [ new AccountPrincipal(devAccount), new AccountPrincipal(testAccount), new AccountPrincipal(prodAccount)];

const transitGWParam = new StringParameter(this, 'transitGWParam', {
    parameterName: 'transitGW',
    stringValue: transitGW.attrId,
});

const transitShareParam = new StringParameter(this, 'transitShareParam', {
    parameterName: 'transitShare',
    stringValue: resourceShare.attrArn,
});

new Role(this,'transitRole',{
    assumedBy: new CompositePrincipal(...principals),
    roleName: 'transit-role-region-1'
}).addToPrincipalPolicy(new PolicyStatement({
    actions: [ 'ssm:GetParameter*' ],
    resources: [ transitGWParam.parameterArn, transitShareParam.parameterArn ]
}));

When in region-2 and in one of the target accounts, to read the parameters value:

const cicdAccount = 12345678;
const cicdRegion = region-1;

const transitGW = new SSMParameterReader(this, 'transitGWReader', {
    parameterName: 'transitGW',
    region: cicdRegion,
    roleArn: `arn:aws:iam::${cicdAccount}:role/transit-role-${cicdRegion}`
}).retrieveParameterValue();

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xregion_ssm_parameter_reader-0.0.5.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xregion_ssm_parameter_reader-0.0.5-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file xregion_ssm_parameter_reader-0.0.5.tar.gz.

File metadata

File hashes

Hashes for xregion_ssm_parameter_reader-0.0.5.tar.gz
Algorithm Hash digest
SHA256 0a789bead76d2acacfeabe7a1af762ea4ac9bfe8de7a7a5c444e8067a3e4545b
MD5 bb13006927b5682a9bbd62ce7f45d6e5
BLAKE2b-256 456a23222a729ef84c6f04aa755aa6d2b874e41613898d04231bbef55e8eb83b

See more details on using hashes here.

File details

Details for the file xregion_ssm_parameter_reader-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for xregion_ssm_parameter_reader-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 49a631574792d7d8f249e7fc9bcd16c614e04d80d1e672563556d630d60d5d2d
MD5 5a15af4dcc7ebde73b756b1df70d74fe
BLAKE2b-256 6dba0602197c280bb1d923696ed2111f3944c1d55aab9f2abcb2e6b6101bb239

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page