Skip to main content

A custom CDK construct to manage a parameter across an AWS account. This construct creates a Lambda-backed custom resource using AWS CloudFormation that handles assuming a role on the target AWS account and puts, updates or deletes a parameter on that account. Role and parameter related variables are passed to the construct and are used by the function to perform these operations.

Project description

Halloumi Cross Account Parameter Store

A custom CDK construct to manage a parameter across an AWS account. This construct creates a Lambda-backed custom resource using AWS CloudFormation that handles assuming a role on the target AWS account and puts, updates or deletes a parameter on that account. Role and parameter related variables are passed to the construct and are used by the function to perform these operations.

Usage

TypeScript

import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import {
  HalloumiCrossAccountParameterStore,
  CustomResourceProvider,
} from 'halloumi-cross-account-parameter-store';

export class MyStack extends Stack {
  constructor(scope: Construct, id: string, props: StackProps = {}) {
    super(scope, id, props);

    const provider = new CustomResourceProvider(
      this,
      'CrossAccountParameterStoreCustomResourceProvider',
      {
        roleArn: 'arn:aws:iam::123412341234:role/role-name',
        roleExternalId: '',
        roleSessionName: '',
      }
    );

    new HalloumiCrossAccountParameterStore(this, 'Parameter1', {
      customResourceProvider: provider,
      parameterName: '/some/parameter/name',
      parameterValue: 'some-value',
      parameterDescription: 'my-description',
    });

    new HalloumiCrossAccountParameterStore(this, 'Parameter2', {
      customResourceProvider: provider,
      parameterName: '/some/parameter/name2',
      parameterValue: 'some-value-2',
      parameterDescription: 'my-description',
    });
  }
}

Python

from aws_cdk import (
    Stack,
)
from halloumi_cross_account_parameter_store import (
    CustomResourceProvider,
    HalloumiCrossAccountParameterStore,
)
from constructs import Construct

class MyStack(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        provider = CustomResourceProvider(
            self,
            "CrossAccountParameterStoreCustomResourceProvider",
            role_arn="arn:aws:iam::123412341234:role/role-name",
            role_external_id="",
            role_session_name="",
        )

        HalloumiCrossAccountParameterStore(
            self,
            "Parameter1",
            custom_resource_provider=provider,
            parameter_name="/some/parameter/name",
            parameter_value="some-value",
            parameter_description="my-description",
        )
        HalloumiCrossAccountParameterStore(
            self,
            "Parameter2",
            custom_resource_provider=provider,
            parameter_name="/some/parameter/name2",
            parameter_value="some-value",
            parameter_description="my-description",
        )

Note: You only need to define the CustomResourceProvider once and pass it to the HalloumiCrossAccountParameterStore constructor of your new instance. If you need to assume different roles, create a new instance of the CustomResourceProvider and use it accordingly.

Setting Up Trust Relationship and the Permissions

The Lambda function role needs to have permission to assume the role in the target account and perform ssm:PutParameter and ssm:DeleteParameter actions. Here's what you need to do to setup the IAM role on the target account that allows the function role on 111111111111 account to create, update or delete parameters with a prefix of /halloumi-cross-account/ on eu-central-1 region. Be sure to adjust the values accordingly.

Trust relationship policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111111111111:root"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "sts:ExternalId": "SET_OR_REMOVE_THE_CONDITION_AND_EXTERNAL_ID_ACCORDINGLY"
        }
      }
    }
  ]
}

Policy Document:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowPutDeleteParameterWithPrefix",
      "Effect": "Allow",
      "Action": ["ssm:PutParameter", "ssm:DeleteParameter"],
      "Resource": "arn:aws:ssm:eu-central-1:YOUR_SANDBOX_ACCOUNT_ID:parameter/halloumi-cross-account/*"
    }
  ]
}

For more information, please check the API Doc

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

halloumi-cross-account-parameter-store-1.0.1.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file halloumi-cross-account-parameter-store-1.0.1.tar.gz.

File metadata

File hashes

Hashes for halloumi-cross-account-parameter-store-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f96600f96e5973fffea7a8c0880297af7a9c8fc91de47e30654476e76a9a0460
MD5 0b98fd30ed2922ae9debb277c7addd64
BLAKE2b-256 b225be9ce2ea70fe7a434d715b2ead829c0b78f46cadb2433ebc29fdb24b4750

See more details on using hashes here.

File details

Details for the file halloumi_cross_account_parameter_store-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for halloumi_cross_account_parameter_store-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7feb5f1f802dc1e83f2832582c48c6cae40b117f2d00562bd7ba770f583fc56e
MD5 92f9fbbd334011a80af3eabe44975224
BLAKE2b-256 b4b9e42026d77d8911d6fadbc318aa3220ccdb80fa39315d5f0d5cc04b2ed23e

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