Skip to content

Commit 0f76294

Browse files
add example for tags, remove existing example (#7987)
* add example for tags, remove existing example * format code using docs prettier * Update src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx Co-authored-by: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> * Update src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx --------- Co-authored-by: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com>
1 parent 5435ce5 commit 0f76294

File tree

3 files changed

+70
-24
lines changed

3 files changed

+70
-24
lines changed

src/directory/directory.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,9 @@ export const directory = {
680680
{
681681
path: 'src/pages/[platform]/build-a-backend/add-aws-services/custom-resources/index.mdx'
682682
},
683+
{
684+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx'
685+
},
683686
{
684687
path: 'src/pages/[platform]/build-a-backend/add-aws-services/overriding-resources/index.mdx'
685688
}

src/pages/[platform]/build-a-backend/add-aws-services/overriding-resources/index.mdx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,4 @@ The `auth.resources.cfnResources.cfnUserPool` property in the above example dire
129129

130130
This is different from `auth.resources.userPool` in the first example, which is an [L2 CDK construct](https://docs.aws.amazon.com/cdk/v2/guide/constructs.html#constructs_using). These are constructs that provide a convenient interface around several related L1 constructs.
131131

132-
## Example - Add tags to resources
133-
134-
```ts title="amplify/backend.ts"
135-
import { defineBackend } from '@aws-amplify/backend';
136-
import { auth } from './auth/resource';
137-
import { data } from './data/resource';
138-
139-
const backend = defineBackend({
140-
auth,
141-
data
142-
});
143-
144-
backend.data.resources.cfnResources.cfnGraphqlApi.addPropertyOverride('Tags', [
145-
{
146-
Key: 'graphqlapi-tag-1',
147-
Value: 'graphql-tag-value-1'
148-
},
149-
{
150-
Key: 'graphqlapi-tag-2',
151-
Value: 'graphql-tag-value-2'
152-
}
153-
]);
154-
```
155-
156132
For situations where you need even more customization of your app backend, see the documentation on [custom resources](/[platform]/build-a-backend/add-aws-services/custom-resources).
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
2+
3+
export const meta = {
4+
title: 'Tagging resources',
5+
description: 'Decorate resources with tags for categorization.',
6+
platforms: [
7+
'android',
8+
'angular',
9+
'flutter',
10+
'javascript',
11+
'nextjs',
12+
'react',
13+
'react-native',
14+
'swift',
15+
'vue'
16+
],
17+
};
18+
19+
export async function getStaticPaths() {
20+
return getCustomStaticPath(meta.platforms);
21+
}
22+
23+
export function getStaticProps(context) {
24+
return {
25+
props: {
26+
platform: context.params.platform,
27+
meta
28+
}
29+
};
30+
}
31+
32+
Tags are a key-value pair that are applied to AWS resources to hold metadata. Tags are often used to decorate resources with metadata that helps categorize resources for billing or viewing purposes. Learn more about tags by visiting the [AWS documentation for best practices for tagging resources](https://docs.aws.amazon.com/whitepapers/latest/tagging-best-practices/what-are-tags.html).
33+
34+
Amplify applies the following tags by default:
35+
36+
| Deployment type | Tag key | Tag value |
37+
|-----------------|---------------------------|--------------------------|
38+
| sandbox | `created-by` | `amplify` |
39+
| sandbox | `amplify:deployment-type` | `sandbox` |
40+
| branch | `created-by` | `amplify` |
41+
| branch | `amplify:deployment-type` | `branch` |
42+
| branch | `amplify:app-id` | `<your-amplify-app-id>` |
43+
| branch | `amplify:branch-name` | `<your-git-branch-name>` |
44+
45+
In your Amplify backend you can use the [`Tags`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Tags.html) class from the [AWS Cloud Development Kit (CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html) to apply tags at the root level, which then cascades to child resources.
46+
47+
```ts title="amplify/backend.ts"
48+
import { Tags } from 'aws-cdk-lib';
49+
import { defineBackend } from '@aws-amplify/backend';
50+
import { auth } from './auth/resource';
51+
import { data } from './data/resource';
52+
53+
/**
54+
* @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more
55+
*/
56+
const backend = defineBackend({
57+
auth,
58+
data
59+
});
60+
61+
const tags = Tags.of(backend.stack);
62+
// add a new tag
63+
tags.add('my-key', 'my-value');
64+
// remove tags
65+
tags.remove('my-key');
66+
```
67+

0 commit comments

Comments
 (0)