cdk-stack-resource-rename
Project description
StackResourceRenamer
A CDK aspect, StackResourceRenamer renames CDK stack name and stack's subordinate resources' custom physical names, so that a CDK stack can be used to create multiple stacks in same AWS environment without confliction.
API: API.md
Samples
typescript
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_stack_resource_rename import StackResourceRenamer
app = core.App()
stack = core.Stack(app, "my-stack")
alias = stack.node.try_get_context("alias")
if alias:
# if alias is defined, rename stack and resources' custom names
StackResourceRenamer.rename(stack,
rename=(origName, _)=>{
return origName+'-'+alias;
}
)
# resources in stack
bucket = s3.Bucket(stack, "bucket",
bucket_name="my-bucket"
)
python
from cdk_stack_resource_rename import (StackResourceRenamer, IRenameOperation)
@jsii.implements(IRenameOperation)
class RenameOper:
def __init__(self, alias):
self.alias=alias
def rename(self, origName, typeName):
return origName+'-'+self.alias
class AppStack(core.Stack):
def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
......
alias = self.node.try_get_context("alias")
if alias != None:
# if alias is defined, rename stack/resources' custom names
StackResourceRenamer.rename(self, RenameOper(alias))
java
import cdkutils.aspects.resourcerename.StackResourceRenamer;
import cdkutils.aspects.resourcerename.IRenameOperation;
public class AppStack extends Stack {
......
String alias = (String) this.getNode().tryGetContext("alias");
if (alias != null) {
StackResourceRenamer.rename(this, new IRenameOperation() {
public String rename(String origName, String typeName) {
return origName + "-"+alias;
}
});
}
To create multiple stacks:
cdk -c alias=a1 deploy
will create a stack: my-stack-a1 with my-bucket-a1.
To create more stacks: my-stack-a2 with my-bucket-a2, my-stack-a3 with my-bucket-a3:
cdk -c alias=a2 deploy
cdk -c alias=a3 deploy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for cdk-stack-resource-rename-0.0.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c8db35753d4f824bc3a92d82bac7346a10c7787037802acaff9509374d87295 |
|
MD5 | c240e246c92ec7cb55a3f58ddf159ed8 |
|
BLAKE2b-256 | 92b4d9521be001e57502b44d7a602ce1e910d7ad6a227f82f6e271808f33e5ee |
Close
Hashes for cdk_stack_resource_rename-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65707ba6081ac896b119d5d5e25f5869e1b883b567eedc0f6ece654a29f3b43b |
|
MD5 | 932238ae46a3a95934defb9fc46523bb |
|
BLAKE2b-256 | 55f7edb3a7da11b85166d4457bd7c48a00d968de1353aa1705a9382cbe0fdd20 |