AWS SDK for JavaScript AppConfig Client for Node.js, Browser and React Native.
AWS AppConfig
Use AWS AppConfig, a capability of AWS Systems Manager, to create, manage, and quickly deploy application configurations. AppConfig supports controlled deployments to applications of any size and includes built-in validation checks and monitoring. You can use AppConfig with applications hosted on Amazon EC2 instances, AWS Lambda, containers, mobile applications, or IoT devices.
To prevent errors when deploying application configurations, especially for production systems where a simple typo could cause an unexpected outage, AppConfig includes validators. A validator provides a syntactic or semantic check to ensure that the configuration you want to deploy works as intended. To validate your application configuration data, you provide a schema or a Lambda function that runs against the configuration. The configuration deployment or update can only proceed when the configuration data is valid.
During a configuration deployment, AppConfig monitors the application to ensure that the deployment is successful. If the system encounters an error, AppConfig rolls back the change to minimize impact for your application users. You can configure a deployment strategy for each application or environment that includes deployment criteria, including velocity, bake time, and alarms to monitor. Similar to error monitoring, if a deployment triggers an alarm, AppConfig automatically rolls back to the previous version.
AppConfig supports multiple use cases. Here are some examples.
-
Application tuning: Use AppConfig to carefully introduce changes to your application that can only be tested with production traffic.
-
Feature toggle: Use AppConfig to turn on new features that require a timely deployment, such as a product launch or announcement.
-
Allow list: Use AppConfig to allow premium subscribers to access paid content.
-
Operational issues: Use AppConfig to reduce stress on your application when a dependency or other external factor impacts the system.
This reference is intended to be used with the AWS AppConfig User Guide.
To install the this package, simply type add or install @aws-sdk/client-appconfig using your favorite package manager:
npm install @aws-sdk/client-appconfig
yarn add @aws-sdk/client-appconfig
pnpm add @aws-sdk/client-appconfig
The AWS SDK is modulized by clients and commands.
To send a request, you only need to import the AppConfigClient
and
the commands you need, for example CreateApplicationCommand
:
// ES5 example
const { AppConfigClient, CreateApplicationCommand } = require("@aws-sdk/client-appconfig");
// ES6+ example
import { AppConfigClient, CreateApplicationCommand } from "@aws-sdk/client-appconfig";
To send a request, you:
- Initiate client with configuration (e.g. credentials, region).
- Initiate command with input parameters.
- Call
send
operation on client with command object as input. - If you are using a custom http handler, you may call
destroy()
to close open connections.
// a client can be shared by different commands.
const client = new AppConfigClient({ region: "REGION" });
const params = {
/** input parameters */
};
const command = new CreateApplicationCommand(params);
We recommend using await operator to wait for the promise returned by send operation as follows:
// async/await.
try {
const data = await client.send(command);
// process data.
} catch (error) {
// error handling.
} finally {
// finally.
}
Async-await is clean, concise, intuitive, easy to debug and has better error handling as compared to using Promise chains or callbacks.
You can also use Promise chaining to execute send operation.
client.send(command).then(
(data) => {
// process data.
},
(error) => {
// error handling.
}
);
Promises can also be called using .catch()
and .finally()
as follows:
client
.send(command)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
})
.finally(() => {
// finally.
});
We do not recommend using callbacks because of callback hell, but they are supported by the send operation.
// callbacks.
client.send(command, (err, data) => {
// proccess err and data.
});
The client can also send requests using v2 compatible style. However, it results in a bigger bundle size and may be dropped in next major version. More details in the blog post on modular packages in AWS SDK for JavaScript
import * as AWS from "@aws-sdk/client-appconfig";
const client = new AWS.AppConfig({ region: "REGION" });
// async/await.
try {
const data = await client.createApplication(params);
// process data.
} catch (error) {
// error handling.
}
// Promises.
client
.createApplication(params)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
});
// callbacks.
client.createApplication(params, (err, data) => {
// proccess err and data.
});
When the service returns an exception, the error will include the exception information, as well as response metadata (e.g. request id).
try {
const data = await client.send(command);
// process data.
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
console.log({ requestId, cfId, extendedRequestId });
/**
* The keys within exceptions are also parsed.
* You can access them by specifying exception names:
* if (error.name === 'SomeServiceException') {
* const value = error.specialKeyInException;
* }
*/
}
Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.
- Visit Developer Guide or API Reference.
- Check out the blog posts tagged with
aws-sdk-js
on AWS Developer Blog. - Ask a question on StackOverflow and tag it with
aws-sdk-js
. - Join the AWS JavaScript community on gitter.
- If it turns out that you may have found a bug, please open an issue.
To test your universal JavaScript code in Node.js, browser and react-native environments, visit our code samples repo.
This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-appconfig
package is updated.
To contribute to client you can check our generate clients scripts.
This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.