From c1b05d504aff42193489b7bb64a38181824b1b64 Mon Sep 17 00:00:00 2001 From: josefaidt Date: Mon, 23 Sep 2024 10:48:36 -0700 Subject: [PATCH 1/4] add example for tags, remove existing example --- src/directory/directory.mjs | 3 + .../overriding-resources/index.mdx | 24 ------- .../tagging-resources/index.mdx | 68 +++++++++++++++++++ 3 files changed, 71 insertions(+), 24 deletions(-) create mode 100644 src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx diff --git a/src/directory/directory.mjs b/src/directory/directory.mjs index 0dea5dcf0c3..6e2a58d2257 100644 --- a/src/directory/directory.mjs +++ b/src/directory/directory.mjs @@ -677,6 +677,9 @@ export const directory = { { path: 'src/pages/[platform]/build-a-backend/add-aws-services/custom-resources/index.mdx' }, + { + path: 'src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx' + }, { path: 'src/pages/[platform]/build-a-backend/add-aws-services/overriding-resources/index.mdx' } diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/overriding-resources/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/overriding-resources/index.mdx index e7cc8162461..b5f5d84942c 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/overriding-resources/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/overriding-resources/index.mdx @@ -134,28 +134,4 @@ The `auth.resources.cfnResources.cfnUserPool` property in the above example dire 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. -## Example - Add tags to resources - -```ts title="amplify/backend.ts" -import { defineBackend } from '@aws-amplify/backend'; -import { auth } from './auth/resource'; -import { data } from './data/resource'; - -const backend = defineBackend({ - auth, - data -}); - -backend.data.resources.cfnResources.cfnGraphqlApi.addPropertyOverride('Tags', [ - { - Key: 'graphqlapi-tag-1', - Value: 'graphql-tag-value-1' - }, - { - Key: 'graphqlapi-tag-2', - Value: 'graphql-tag-value-2' - } -]); -``` - 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). diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx new file mode 100644 index 00000000000..d59972f3216 --- /dev/null +++ b/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx @@ -0,0 +1,68 @@ +import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; + +export const meta = { + title: 'Tagging resources', + description: 'Decorate resources with tags for categorization.', + platforms: [ + 'android', + 'angular', + 'flutter', + 'javascript', + 'nextjs', + 'react', + 'react-native', + 'swift', + 'vue' + ], +}; + +export async function getStaticPaths() { + return getCustomStaticPath(meta.platforms); +} + +export function getStaticProps(context) { + return { + props: { + platform: context.params.platform, + meta + } + }; +} + +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). + +Amplify applies the following tags by default: + +| Deployment type | Tag key | Tag value | +|-----------------|---------------------------|--------------------------| +| sandbox | `created-by` | `amplify` | +| sandbox | `amplify:deployment-type` | `sandbox` | +| branch | `created-by` | `amplify` | +| branch | `amplify:deployment-type` | `branch` | +| branch | `amplify:app-id` | `` | +| branch | `amplify:branch-name` | `` | + +In your Amplify backend your 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 cascades tag application to child resources. + +```ts title="amplify/backend.ts" +import { Tags } from "aws-cdk-lib" +import { defineBackend } from "@aws-amplify/backend" +import { auth } from "./auth/resource" +import { data } from "./data/resource" + +/** + * @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more + */ +const backend = defineBackend({ + auth, + data, +}) + +const tags = Tags.of(backend.stack) +// add a new tag +tags.add("my-key", "my-value") +// remove tags +tags.remove("my-key") +``` + +{/* Alternatively you can apply tags to individual resource stacks... */} From 5dda85232cd02526663ee74ad02dff093611b633 Mon Sep 17 00:00:00 2001 From: josefaidt Date: Mon, 23 Sep 2024 10:53:00 -0700 Subject: [PATCH 2/4] format code using docs prettier --- .../tagging-resources/index.mdx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx index d59972f3216..b30100c479d 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx @@ -45,24 +45,24 @@ Amplify applies the following tags by default: In your Amplify backend your 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 cascades tag application to child resources. ```ts title="amplify/backend.ts" -import { Tags } from "aws-cdk-lib" -import { defineBackend } from "@aws-amplify/backend" -import { auth } from "./auth/resource" -import { data } from "./data/resource" +import { Tags } from 'aws-cdk-lib'; +import { defineBackend } from '@aws-amplify/backend'; +import { auth } from './auth/resource'; +import { data } from './data/resource'; /** * @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more */ const backend = defineBackend({ auth, - data, -}) + data +}); -const tags = Tags.of(backend.stack) +const tags = Tags.of(backend.stack); // add a new tag -tags.add("my-key", "my-value") +tags.add('my-key', 'my-value'); // remove tags -tags.remove("my-key") +tags.remove('my-key'); ``` {/* Alternatively you can apply tags to individual resource stacks... */} From cfb0c7f58fd1ef85655a79b2d259a2bab6f8f282 Mon Sep 17 00:00:00 2001 From: josef Date: Tue, 24 Sep 2024 08:06:05 -0700 Subject: [PATCH 3/4] Update src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx Co-authored-by: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> --- .../add-aws-services/tagging-resources/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx index b30100c479d..6c539902a01 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx @@ -42,7 +42,7 @@ Amplify applies the following tags by default: | branch | `amplify:app-id` | `` | | branch | `amplify:branch-name` | `` | -In your Amplify backend your 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 cascades tag application to child resources. +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. ```ts title="amplify/backend.ts" import { Tags } from 'aws-cdk-lib'; From 456f7bf9517d1283b3f4a78337cebd0690f409f4 Mon Sep 17 00:00:00 2001 From: josef Date: Tue, 24 Sep 2024 08:09:32 -0700 Subject: [PATCH 4/4] Update src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx --- .../build-a-backend/add-aws-services/tagging-resources/index.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx index 6c539902a01..84c44dca36a 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/tagging-resources/index.mdx @@ -65,4 +65,3 @@ tags.add('my-key', 'my-value'); tags.remove('my-key'); ``` -{/* Alternatively you can apply tags to individual resource stacks... */}