Skip to content

Commit

Permalink
feat(appconfig-alpha): support for relative file paths when importing…
Browse files Browse the repository at this point in the history
… config (#28191)

When importing a config from a file, you can now pass a relative path (`config.json`) instead of the absolute path (`/Users/..../config.json`).

Closes #26937.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
chenjane-dev committed Dec 5, 2023
1 parent c8627ce commit 4867294
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 35 deletions.
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-appconfig-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {

You can define hosted configuration content using any of the following ConfigurationContent methods:

* `fromFile` - Defines the hosted configuration content from a file.
* `fromFile` - Defines the hosted configuration content from a file (you can specify a relative path).
* `fromInlineText` - Defines the hosted configuration from inline text.
* `fromInlineJson` - Defines the hosted configuration from inline JSON.
* `fromInlineYaml` - Defines the hosted configuration from inline YAML.
Expand Down Expand Up @@ -121,6 +121,8 @@ configuration data is syntactically and semantically correct. You can create val
Lambda function.
See [About validators](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-creating-configuration-and-profile.html#appconfig-creating-configuration-and-profile-validators) for more information.

When you import a JSON Schema validator from a file, you can pass in a relative path.

A hosted configuration with validators:

```ts
Expand Down
15 changes: 8 additions & 7 deletions packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import * as mimeTypes from 'mime-types';
import * as path from 'path';
import { PhysicalName, Stack, ArnFormat, Names, RemovalPolicy } from 'aws-cdk-lib';
import { CfnConfigurationProfile, CfnDeployment, CfnHostedConfigurationVersion } from 'aws-cdk-lib/aws-appconfig';
import * as cp from 'aws-cdk-lib/aws-codepipeline';
Expand Down Expand Up @@ -766,11 +767,11 @@ export abstract class JsonSchemaValidator implements IValidator {
/**
* Defines a JSON Schema validator from a file.
*
* @param path The path to the file that defines the validator
* @param inputPath The path to the file that defines the validator
*/
public static fromFile(path: string): JsonSchemaValidator {
public static fromFile(inputPath: string): JsonSchemaValidator {
return {
content: fs.readFileSync(path).toString(),
content: fs.readFileSync(path.resolve(inputPath)).toString(),
type: ValidatorType.JSON_SCHEMA,
};
}
Expand Down Expand Up @@ -824,13 +825,13 @@ export abstract class ConfigurationContent {
/**
* Defines the hosted configuration content from a file.
*
* @param path The path to the file that defines configuration content
* @param inputPath The path to the file that defines configuration content
* @param contentType The content type of the configuration
*/
public static fromFile(path: string, contentType?: string): ConfigurationContent {
public static fromFile(inputPath: string, contentType?: string): ConfigurationContent {
return {
content: fs.readFileSync(path).toString(),
contentType: contentType || mimeTypes.lookup(path) || 'application/json',
content: fs.readFileSync(path.resolve(inputPath)).toString(),
contentType: contentType || mimeTypes.lookup(inputPath) || 'application/json',
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ describe('configuration', () => {
}),
}),
application: app,
content: ConfigurationContent.fromFile('./test/config.json'),
content: ConfigurationContent.fromFile('test/config.json'),
});

Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::ConfigurationProfile', {
Expand Down Expand Up @@ -763,6 +763,7 @@ describe('configuration', () => {
application: app,
validators: [
JsonSchemaValidator.fromInline(validatorContent),
JsonSchemaValidator.fromFile('test/schema.json'),
],
content: ConfigurationContent.fromInlineText('This is my content'),
deploymentStrategy: new DeploymentStrategy(stack, 'MyDeploymentStrategy', {
Expand All @@ -783,6 +784,10 @@ describe('configuration', () => {
Type: 'JSON_SCHEMA',
Content: '\n {\n \"type\": \"object\",\n \"properties\": {\n \"computeResource\": {\n \"type\": \"object\",\n \"properties\": {\n \"ComputeAL1ImageId\": {\n \"type\": \"object\",\n \"properties\": {\n \"me-south-1\": { \"type\": \"string\" },\n \"ap-east-1\": { \"type\": \"string\" },\n \"ap-northeast-1\": { \"type\": \"string\" },\n \"ap-northeast-2\": { \"type\": \"string\" },\n \"ap-south-1\": { \"type\": \"string\" },\n \"ap-southeast-1\": { \"type\": \"string\" },\n \"ap-southeast-2\": { \"type\": \"string\" },\n \"ca-central-1\": { \"type\": \"string\" },\n \"cn-north-1\": { \"type\": \"string\" },\n \"cn-northwest-1\": { \"type\": \"string\" },\n \"eu-central-1\": { \"type\": \"string\" },\n \"eu-north-1\": { \"type\": \"string\" },\n \"eu-west-1\": { \"type\": \"string\" },\n \"eu-west-2\": { \"type\": \"string\" },\n \"eu-west-3\": { \"type\": \"string\" },\n \"sa-east-1\": { \"type\": \"string\" },\n \"us-east-1\": { \"type\": \"string\" },\n \"us-east-2\": { \"type\": \"string\" },\n \"us-gov-west-1\": { \"type\": \"string\" },\n \"us-gov-east-1\": { \"type\": \"string\" },\n \"us-west-1\": { \"type\": \"string\" },\n \"us-west-2\": { \"type\": \"string\" },\n \"eu-south-1\": { \"type\": \"string\" },\n \"ap-northeast-3\": { \"type\": \"string\" },\n \"af-south-1\": { \"type\": \"string\" }\n }\n },\n \"GPUImageId\": {\n \"type\": \"object\",\n \"properties\": {\n \"me-south-1\": { \"type\": \"string\" },\n \"ap-east-1\": { \"type\": \"string\" },\n \"ap-northeast-1\": { \"type\": \"string\" },\n \"ap-northeast-2\": { \"type\": \"string\" },\n \"ap-south-1\": { \"type\": \"string\" },\n \"ap-southeast-1\": { \"type\": \"string\" },\n \"ap-southeast-2\": { \"type\": \"string\" },\n \"ca-central-1\": { \"type\": \"string\" },\n \"cn-north-1\": { \"type\": \"string\" },\n \"cn-northwest-1\": { \"type\": \"string\" },\n \"eu-central-1\": { \"type\": \"string\" },\n \"eu-north-1\": { \"type\": \"string\" },\n \"eu-west-1\": { \"type\": \"string\" },\n \"eu-west-2\": { \"type\": \"string\" },\n \"eu-west-3\": { \"type\": \"string\" },\n \"sa-east-1\": { \"type\": \"string\" },\n \"us-east-1\": { \"type\": \"string\" },\n \"us-east-2\": { \"type\": \"string\" },\n \"us-gov-west-1\": { \"type\": \"string\" },\n \"us-gov-east-1\": { \"type\": \"string\" },\n \"us-west-1\": { \"type\": \"string\" },\n \"us-west-2\": { \"type\": \"string\" },\n \"eu-south-1\": { \"type\": \"string\" },\n \"ap-northeast-3\": { \"type\": \"string\" },\n \"af-south-1\": { \"type\": \"string\" }\n }\n },\n \"ARMImageId\": {\n \"type\": \"object\",\n \"properties\": {\n \"me-south-1\": { \"type\": \"string\" },\n \"ap-east-1\": { \"type\": \"string\" },\n \"ap-northeast-1\": { \"type\": \"string\" },\n \"ap-northeast-2\": { \"type\": \"string\" },\n \"ap-south-1\": { \"type\": \"string\" },\n \"ap-southeast-1\": { \"type\": \"string\" },\n \"ap-southeast-2\": { \"type\": \"string\" },\n \"ca-central-1\": { \"type\": \"string\" },\n \"cn-north-1\": { \"type\": \"string\" },\n \"cn-northwest-1\": { \"type\": \"string\" },\n \"eu-central-1\": { \"type\": \"string\" },\n \"eu-north-1\": { \"type\": \"string\" },\n \"eu-west-1\": { \"type\": \"string\" },\n \"eu-west-2\": { \"type\": \"string\" },\n \"eu-west-3\": { \"type\": \"string\" },\n \"sa-east-1\": { \"type\": \"string\" },\n \"us-east-1\": { \"type\": \"string\" },\n \"us-east-2\": { \"type\": \"string\" },\n \"us-gov-west-1\": { \"type\": \"string\" },\n \"us-gov-east-1\": { \"type\": \"string\" },\n \"us-west-1\": { \"type\": \"string\" },\n \"us-west-2\": { \"type\": \"string\" },\n \"eu-south-1\": { \"type\": \"string\" },\n \"ap-northeast-3\": { \"type\": \"string\" },\n \"af-south-1\": { \"type\": \"string\" }\n }\n },\n \"ComputeAL2ImageId\": {\n \"type\": \"object\",\n \"properties\": {\n \"me-south-1\": { \"type\": \"string\" },\n \"ap-east-1\": { \"type\": \"string\" },\n \"ap-northeast-1\": { \"type\": \"string\" },\n \"ap-northeast-2\": { \"type\": \"string\" },\n \"ap-south-1\": { \"type\": \"string\" },\n \"ap-southeast-1\": { \"type\": \"string\" },\n \"ap-southeast-2\": { \"type\": \"string\" },\n \"ca-central-1\": { \"type\": \"string\" },\n \"cn-north-1\": { \"type\": \"string\" },\n \"cn-northwest-1\": { \"type\": \"string\" },\n \"eu-central-1\": { \"type\": \"string\" },\n \"eu-north-1\": { \"type\": \"string\" },\n \"eu-west-1\": { \"type\": \"string\" },\n \"eu-west-2\": { \"type\": \"string\" },\n \"eu-west-3\": { \"type\": \"string\" },\n \"sa-east-1\": { \"type\": \"string\" },\n \"us-east-1\": { \"type\": \"string\" },\n \"us-east-2\": { \"type\": \"string\" },\n \"us-gov-west-1\": { \"type\": \"string\" },\n \"us-gov-east-1\": { \"type\": \"string\" },\n \"us-west-1\": { \"type\": \"string\" },\n \"us-west-2\": { \"type\": \"string\" },\n \"eu-south-1\": { \"type\": \"string\" },\n \"ap-northeast-3\": { \"type\": \"string\" },\n \"af-south-1\": { \"type\": \"string\" }\n }\n }\n }\n }\n }\n }',
},
{
Type: 'JSON_SCHEMA',
Content: '{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"type\": \"string\"\n}',
},
],
LocationUri: 'hosted',
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,42 @@
"ReplicateTo": "NONE"
}
},
"MyHostedConfigFromFileDeploymentStrategyCAF37A7C": {
"Type": "AWS::AppConfig::DeploymentStrategy",
"Properties": {
"DeploymentDurationInMinutes": 20,
"FinalBakeTimeInMinutes": 10,
"GrowthFactor": 10,
"GrowthType": "EXPONENTIAL",
"Name": "awsappconfigconfiguration-MyFromFile-DeploymentStrategy-C2367737",
"ReplicateTo": "NONE"
}
},
"MyHostedConfigFromFileConfigurationProfile32B2D26F": {
"Type": "AWS::AppConfig::ConfigurationProfile",
"Properties": {
"ApplicationId": {
"Ref": "MyAppConfigB4B63E75"
},
"LocationUri": "hosted",
"Name": "awsappconfigconfiguration-MyHostedConfigFromFile-8ED1123C"
}
},
"MyHostedConfigFromFile943CF9F9": {
"Type": "AWS::AppConfig::HostedConfigurationVersion",
"Properties": {
"ApplicationId": {
"Ref": "MyAppConfigB4B63E75"
},
"ConfigurationProfileId": {
"Ref": "MyHostedConfigFromFileConfigurationProfile32B2D26F"
},
"Content": "{\n \"content\": \"This is the configuration content\"\n}",
"ContentType": "application/json"
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyHostedConfigConfigurationProfile2E1A2BBC": {
"Type": "AWS::AppConfig::ConfigurationProfile",
"Properties": {
Expand All @@ -97,6 +133,10 @@
"LocationUri": "hosted",
"Name": "awsappconfigconfiguration-MyHostedConfig-4CF350AE",
"Validators": [
{
"Content": "{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"type\": \"string\"\n}",
"Type": "JSON_SCHEMA"
},
{
"Content": "{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"type\": \"string\"\n}",
"Type": "JSON_SCHEMA"
Expand Down Expand Up @@ -565,7 +605,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "e2277687077a2abf9ae1af1cc9565e6715e2ebb62f79ec53aa75a1af9298f642.zip"
"S3Key": "3fb6287214999ddeafa7cd0e3e58bc5144c8678bb720f3b5e45e8fd32f333eb3.zip"
},
"Description": "/opt/awscli/aws"
}
Expand Down Expand Up @@ -736,7 +776,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "9eb41a5505d37607ac419321497a4f8c21cf0ee1f9b4a6b29aa04301aea5c7fd.zip"
"S3Key": "e976a796f036a5efbf44b99e44cfb5a961df08d8dbf7cd37e60bf216fb982a00.zip"
},
"Environment": {
"Variables": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4867294

Please sign in to comment.