cdk-stack-resource-rename
Project description
StackResourceRenamer
A CDK aspect, StackResourceRenamer renames CDK stack name and stack's subordinate resources' physical names, so that a CDK stack can be used to create multiple stacks in same AWS environment without confliction.
API: API.md
Two main use cases:
- rename custom resources names in stack, so that stack can be reused and replicated:
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
StackResourceRenamer.rename(stack,
rename=(resName, _)=>{
return resName+'-'+alias;
}
)
- for resources without custom name, which by default will use unique id AWS auto generate as its physical id, we can create a more readable and identifiable name, for testing, debugging or metrics monitoring environments.
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
StackResourceRenamer.rename(stack, {
"rename": (_, typeName)=>{
counts[typeName]++;
return projectName+'-'+serviceName+'-'+typeName+'-'+counts[typeName];
}
}, user_custom_name_only=False)
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=(resName, _)=>{
return resName+'-'+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, resName, typeName):
return resName+'-'+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 io.github.yglcode.cdkutils.aspects.resourcerename.StackResourceRenamer;
import io.github.yglcode.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 resName, String typeName) {
return resName + "-"+alias;
}
});
}
csharp
using CdkUtils.Aspects.ResourceRename;
public class RenameOper: Amazon.JSII.Runtime.Deputy.DeputyBase, IRenameOperation {
private string alias;
public RenameOper(string alias) {
this.alias=alias;
}
public string Rename(string resName, string typeName) {
return resName+"-"+alias;
}
}
public class AppStack : Stack
{
internal AppStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
{
......
var alias = (string)this.Node.TryGetContext("alias");
if (alias!=null) {
StackResourceRenamer.Rename(this, new RenameOper(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.17.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c4414ecf7bebfb9d8e202f7e5b643eeca5044a2690baa2691af209cabe7dc10 |
|
MD5 | 4caba5486f208dc057daa6a017a1b296 |
|
BLAKE2b-256 | db1fead817c568940340bd99b45ba2b99f43adb5f015a19cc3ca7782b29dcd4d |
Close
Hashes for cdk_stack_resource_rename-0.0.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a984cbc7bb4cd7ac4feb26a35f6c7d35feae05e3b225fbfca7b41b751495c853 |
|
MD5 | 36f98c3a5078d32124ba2cda6654288d |
|
BLAKE2b-256 | 69d6fac05fe783a18d1840c7e5b0933c689bf8554803041d788b17a97bc98e1c |