Skip to content

5. Using Aliases

mkutsybala edited this page Oct 8, 2024 · 10 revisions
Navigation:

5.1 Static Aliases

5.2 Dynamic Aliases

The deployment framework can work with static and dynamic aliases for referencing deployed resources.

Each alias type usage details are given further in this section.

5.1 Static Aliases

The aliases are used for reference the alias value in the resources configuration.

An alias can be used to pass the resource name to the lambda function environment variable, it is very useful in case of extended prefix mode in the project because of automatic resource name resolving.

The aliases are stored in the file syndicate_aliases.yml inside the project configuration directory.

Access to the alias value by the name using the next syntax "${alias_name}"

Usage examples

Python, NodeJS, .NET

#1: To configure the lambda function log expiration period via syndicate alias

  • set up an alias by adding a key-value pair to the file syndicate_aliases.yml
	logs_expiration: 30
  • Refer to the alias by name in the file lambda_config.json
	{
	  "version": "1.0",
	  "name": "demo",
	  "func_name": "handler.lambda_handler",
	  "resource_type": "lambda",
	  "iam_role_name": "demo-role",
	  "runtime": "python3.10",
	  "memory": 128,
	  "timeout": 100,
	  "lambda_path": "lambdas\\demo",
	  "dependencies": [],
	  "event_sources": [],
	  "env_variables": {},
	  "publish_version": false,
	  "url_config": {},
	  "ephemeral_storage": 512,
	  "logs_expiration": "${logs_expiration}",
	  "layers": []
	}

#2: To configure the dynamodb table name via syndicate aliases and set up it as a lambda function environment variable

  • set up an alias by adding a key-value pair to the file syndicate_aliases.yml
	demo_table: Demo-table
  • Refer to the alias by name in the file deployment_resources.json to set the table name via the alias
	{
		"${demo_table}": {
		"resource_type": "dynamodb_table",
		"hash_key_name": "id",
		"hash_key_type": "N",
		"read_capacity": 1,
		"write_capacity": 1,
		"global_indexes": [
		  {
			"name": "number-index",
			"index_key_name": "number",
			"index_key_type": "N"
		  }
		],
		"autoscaling": []
	  }
	}
  • Refer to the alias by name in the file lambda_config.json to set up the lambda function environment variable with the table name.

Pay attention that the table name will be with the prefix and/or the suffix if prefixes and/or suffixes are configured in the project and extended prefix mode is enabled.

During the deployment, the environment variable with the name 'demo_table_name' that contains the actual dynamodb table name will be set in the lambda function environment.

	{
	  "version": "1.0",
	  "name": "demo",
	  "func_name": "handler.lambda_handler",
	  "resource_type": "lambda",
	  "iam_role_name": "demo-role",
	  "runtime": "python3.10",
	  "memory": 128,
	  "timeout": 100,
	  "lambda_path": "lambdas\\demo",
	  "dependencies": [],
	  "event_sources": [],
	  "env_variables": {
		"demo_table_name": "${demo_table}"
	  },
	  "publish_version": false,
	  "url_config": {},
	  "ephemeral_storage": 512,
	  "layers": []
	}

Java

#1. To configure the lambda function log expiration period via syndicate alias:

  • set up a static alias by adding a key-value pair to the file syndicate_aliases.yml
	logs_expiration: 30
  • refer to the static alias by predefined enum value in the @LambdaHandler annotation
	@LambdaHandler(
        logsExpiration = RetentionSetting.SYNDICATE_ALIASES_SPECIFIED,
        ...
	)

#2. Configure the region and the bucket name via static aliases and set them up as a lambda function environment variables:

  • set up a static alias by adding a key-value pairs into the file syndicate_aliases.yml
	region: eu-central-1
	notification_bucket: demo-example-notification-bucket
  • refer to the static alias by name in the file deployment_resources.json to set the bucket name via the static alias
	{
	  ${notification_bucket}": {
		"resource_type": "s3_bucket"
	  }
	}
  • refer to the aliases by names in the @EnvironmentVariable annotation:
	@EnvironmentVariables(value = {
        @EnvironmentVariable(key = "region", value = "${region}"),
        @EnvironmentVariable(key = "notification_bucket", value = "${notification_bucket}")
	})

5.2 Dynamic Aliases

The dynamic aliases are used for the cases when you need to reference the IDs of the resources after these resources are deployed.

A dynamic alias is set within the meta description of the AWS resource that influences the alias value. It is described in the apply_changes attribute in the Operation Files.

Currently, dynamic aliases are supported for two types of resources. For each resource type, you need to provide specific details:

IAM Policy alias:

  • Action: apply_type: iam_policy
  • Dependency name
  • Policy Content

IAM Role alias:

  • Action: apply_type:iam_role
  • Dependency name
  • Trusted relationships

The resource name in alias is specified as #{resource_name}. For API Gateway and Cognito, this line is further transformed into a resource ID, generated by AWS during the deployment.

For example (see the screenshot below): you have an IAM policy (1) and an API Gateway (2) described in the deployment_resources.json. After the API gateway is deployed, you need to dynamically update the policy by adding the API Gateway ID which can be retrieved only after the gateway is deployed. To do this, you specify the apply_changes attribute (3) in the API Gateway description. The attribute links the changes to the target policy (4,5) :

Figure 1 - Setting a dynamic alias


The complete deployment_resources.json file with the dynamic alias description can be found in the examples folder.


5.3 Static Aliases

LEGACY

Legacy

Note: This section (5.3 Static Aliases) is considered outdated. For current standards, refer to updated section.

The static aliases can be used for convenient distinction of infrastructures that are deployed from the same meta descriptions but need to have different resource naming in AWS.

For example, this can be used in setting up similar prod and dev environments, or deploying infrastructure in different regions or accounts.

The static aliases are described in the sdct_aliases.conf file which must be placed in the same directory with the sdct.conf file.

The sdct_aliases.conf includes the key-value list of aliases, for example:

dev_notification_bucket=notification-temp

During the deployment, the name, specified in the meta description as ${dev_notification_bucket} will be replaced with ‘notification-temp’.