Using aws appconfig with schemas
TypeScriptAWS AppConfig is a capability within Amazon Web Services that enables you to create, manage, and quickly deploy application configurations without causing downtime to your application. AppConfig supports controlled deployments to applications of any size and includes built-in validation checks and monitoring. You can use AWS AppConfig with AWS Lambda, Amazon ECS, Amazon EC2, and on-premises servers, or you can build your own integrators.
Here, I will show you how you can create an AWS AppConfig application, an environment within that application, and associate it with an AWS AppConfig configuration profile using Pulumi in TypeScript. This code assumes that you've already configured the AWS provider for Pulumi.
We'll be creating a few resources here:
aws.appconfig.Application
: Represents an AWS AppConfig application. This is a logical unit of code that provides capabilities for dynamic configuration.aws.appconfig.Environment
: An environment is a logical deployment group of AppConfig applications, such asproduction
,development
, andtest
.aws.appconfig.ConfigurationProfile
: A configuration profile within an application to which you can associate configuration data, in this case, a schema.
The schema could be provided inline or sourced from an existing AWS Schemas Discoverer or Schema Definition. For the purpose of this code, we assume that you want to store your schema inside the AppConfig Configuration Profile as a JSON string.
First, we need to define the application and environment. After these resources are created, we will create an AppConfig configuration profile to store the schema.
import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws"; // Create an AppConfig Application const app = new aws.appconfig.Application("myAppConfigApp", { // Set the fields for the AppConfig application name: "MyApp", // The name of the application description: "My application that will use AppConfig", // An optional description }); // Create an AppConfig Environment const environment = new aws.appconfig.Environment("myAppConfigEnvironment", { // Set the fields for the AppConfig environment name: "production", // The name of the environment description: "The production environment", // An optional description applicationId: app.id, // Reference to the application ID created above }); // Create an AppConfig Configuration Profile with a schema const configProfile = new aws.appconfig.ConfigurationProfile("myAppConfigProfile", { // Set the fields for the AppConfig configuration profile name: "MyProfile", // The name of the configuration profile applicationId: app.id, // Reference to the application ID created above locationUri: "hosted", // Indicates the configuration profile is an AWS hosted configuration // Here you would put your schema data inline // This is a simplified example and assumes a JSON schema // For production, you should validate and test the JSON schema thoroughly retrievalRoleArn: "<arn-of-role-with-permission-to-retrieve-config>", // Replace with the proper ARN validators: [{ content: JSON.stringify({ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Product", "description": "A product in the catalog", "type": "object", "properties": { "id": { "description": "The unique identifier for a product", "type": "integer" }, "name": { "description": "Name of the product", "type": "string" }, "price": { "description": "The price of the product", "type": "number", "exclusiveMinimum": 0 } }, "required": ["id", "name", "price"] }), type: "JSON_SCHEMA", // The type of validator, in this case, a JSON schema validator }], }); // Output the AppConfig application and environment IDs // These can be used to reference the AppConfig resources created export const appId = app.id; export const environmentId = environment.id;
Replace
<arn-of-role-with-permission-to-retrieve-config>
with the appropriate Role ARN that has permissions to retrieve the configuration.That's it! With those few steps, you've created an AppConfig application, an environment to deploy to, and a configuration profile with a schema to ensure your configuration data's integrity using AWS with Pulumi. Each resource is interconnected, and Pulumi is aware of these dependencies, so it creates them in the correct order.
This is a simple example to get you started. In production scenarios, you may want to create more elaborate schemas, add validation, link to configuration data stored in Amazon S3, and implement deployment strategies. With Pulumi, you can expand this further to include all of those aspects as needed.