@backstage/integration-aws-node
This package providers helpers for fetching AWS account credentials
to be used by AWS SDK clients in backend packages and plugins.
Backstage app configuration
Users of plugins and packages that use this library
will configure their AWS account information and credentials in their
Backstage app config.
Users can configure IAM user credentials, IAM roles, and profile names
for their AWS accounts in their Backstage config.
If the AWS integration configuration is missing, the credentials manager
from this package will fall back to the AWS SDK default credentials chain for
resources in the main AWS account.
The default credentials chain for Node resolves credentials in the
following order of precedence:
- Environment variables
- SSO credentials from token cache
- Web identity token credentials
- Shared credentials files
- The EC2/ECS Instance Metadata Service
See more about the AWS SDK default credentials chain in the
AWS SDK for Javascript Developer Guide.
Configuration examples:
aws:
mainAccount:
accessKeyId: ${MY_ACCESS_KEY_ID}
secretAccessKey: ${MY_SECRET_ACCESS_KEY}
accounts:
- accountId: '111111111111'
roleName: 'my-iam-role-name'
externalId: 'my-external-id'
- accountId: '222222222222'
partition: 'aws-other'
roleName: 'my-iam-role-name'
region: 'not-us-east-1'
accessKeyId: ${MY_ACCESS_KEY_ID_FOR_ANOTHER_PARTITION}
secretAccessKey: ${MY_SECRET_ACCESS_KEY_FOR_ANOTHER_PARTITION}
- accountId: '333333333333'
accessKeyId: ${MY_OTHER_ACCESS_KEY_ID}
secretAccessKey: ${MY_OTHER_SECRET_ACCESS_KEY}
- accountId: '444444444444'
profile: my-profile-name
- accountId: '555555555555'
accountDefaults:
roleName: 'my-backstage-role'
externalId: 'my-id'
Integrate new plugins
Backend plugins can provide an AWS ARN or account ID to this library in order to
retrieve a credential provider for the relevant account that can be fed directly
to an AWS SDK client.
The AWS SDK for Javascript V3 must be used.
const awsCredentialsManager = DefaultAwsCredentialsManager.fromConfig(config);
const credProvider = await awsCredentialsManager.getCredentialProvider({
accountId,
});
const credProvider = await awsCredentialsManager.getCredentialProvider({ arn });
const credProvider = await awsCredentialsManager.getCredentialProvider({});
const client = new ProtonClient({
region,
credentialDefaultProvider: () => credProvider.sdkCredentialProvider,
});
Depending on the nature of your plugin, you may either have the user specify the
relevant ARN or account ID in a catalog entity annotation or in the static Backstage
app configuration for your plugin.
For example, you can create a new catalog entity annotation for your plugin containing
either an AWS account ID or ARN:
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
annotations:
my-plugin.io/aws-account-id: '123456789012'
my-other-plugin.io/aws-dynamodb-table: 'arn:aws:dynamodb:us-east-2:123456789012:table/example-table'
In your plugin, read the annotation value so that you can retrieve the credential provider:
const MY_AWS_ACCOUNT_ID_ANNOTATION = 'my-plugin.io/aws-account-id';
const getAwsAccountId = (entity: Entity) =>
entity.metadata.annotations?.[MY_AWS_ACCOUNT_ID_ANNOTATION]);
Alternatively, you can create a new Backstage app configuration field for your plugin:
my-plugin:
awsAccountId: '123456789012'
my-other-plugin:
awsDynamoDbTable: 'arn:aws:dynamodb:us-east-2:123456789012:table/example-table'
In your plugin, read the configuration value so that you can retrieve the credential provider:
const awsCredentialsManager = DefaultAwsCredentialsManager.fromConfig(config);
const accountId = config.getOptionalString('my-plugin.awsAccountId');
const credProvider = await awsCredentialsManager.getCredentialProvider({
accountId,
});
const awsCredentialsManager = DefaultAwsCredentialsManager.fromConfig(config);
const arn = config.getString('my-other-plugin.awsDynamoDbTable');
const credProvider = await awsCredentialsManager.getCredentialProvider({ arn });
Links