amplify-backend icon indicating copy to clipboard operation
amplify-backend copied to clipboard

Create Amplify resources in acc to Control Tower enforced policies

Open vishal-dms opened this issue 1 year ago • 3 comments

Environment information

N/A

Description

S3 buckets used for storing metadata like data schema does not follow Control Tower enforced policies as they are the best recommendations documented by AWS -

For e.g. the buckets don't have the following -

  • There's no versioning enabled.
  • No logging policy is applied.

This discrepancy between AWS's recommended deployment practices with Amplify Gen 2 vs the Control Tower's enforced policies

https://docs.aws.amazon.com/controltower/latest/controlreference/s3-rules.html

Same as Gen1 FR - https://github.com/aws-amplify/amplify-cli/issues/13617

vishal-dms avatar May 28 '24 04:05 vishal-dms

Hey, thank you for filing this feature request. Marking this as feature request for further prioritization by the Amplify team.

ykethan avatar May 28 '24 13:05 ykethan

Hi any update here? thanks

jposadaa avatar Apr 04 '25 17:04 jposadaa

The following workaround can be used meanwhile.

import { defineBackend } from '@aws-amplify/backend';
import { auth } from './auth/resource';
import { data } from './data/resource';
import { Aspects } from 'aws-cdk-lib';
import { IConstruct } from 'constructs';
import { Bucket, CfnBucket } from "aws-cdk-lib/aws-s3";
import {Effect, PolicyStatement, StarPrincipal} from 'aws-cdk-lib/aws-iam';

/**
 * @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more
 */
const backend = defineBackend({
    auth,
    data,
});

Aspects.of(backend.stack).add({
    visit(node: IConstruct) {
        if (node instanceof Bucket) {
            node.addToResourcePolicy(
                new PolicyStatement({
                    effect: Effect.DENY,
                    principals: [new StarPrincipal()],
                    resources: [node.bucketArn + "/*"],
                    actions: ["s3:*"],
                    conditions: {
                        "Bool": {
                            "aws:SecureTransport": false
                        }
                    }
                })
            );

            (node.node.defaultChild as CfnBucket).addPropertyOverride('VersioningConfiguration', {
                Status: 'Enabled'
            });
        }
    },
});

sobolk avatar Jun 12 '25 18:06 sobolk