Skip to content

AWS amplify app + AWS S3

0

I need to create the following using cloudformation template.

  • one S3 bucket to store the files
  • AWS amplify app which uses the files stored in this S3 bucket to present on the app.

I want this app to be setup in 100 different AWS accounts with different S3, amplify apps

1 Answer
0

it be worth trying this

To create an S3 bucket and an Amplify app that uses the files stored in the S3 bucket, and then deploy this setup across 100 different AWS accounts, you can use AWS CloudFormation templates.

Here's an example CloudFormation template that creates an S3 bucket and an Amplify app:

AWSTemplateFormatVersion: '2010-09-09'
Description: Create an S3 bucket and an Amplify app

Parameters:
  BucketName:
    Type: String
    Description: Name of the S3 bucket to create
  AppName:
    Type: String
    Description: Name of the Amplify app to create

Resources:

  # S3 Bucket
  MyS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref BucketName
      PublicAccessBlockConfiguration:
        BlockPublicAcls: true
        BlockPublicPolicy: true
        IgnorePublicAcls: true
        RestrictPublicBuckets: true

  # Amplify App
  MyAmplifyApp:
    Type: AWS::Amplify::App
    Properties:
      AppName: !Ref AppName
      AutoBranchCreationConfig:
        BasicAuthConfig:
          EnableBasicAuth: false
        BuildSpec: |
          version: 1
          frontend:
            phases:
              preBuild:
                commands:
                  - npm ci
              build:
                commands:
                  - npm run build
            artifacts:
              baseDirectory: build
              files:
                - '**/*'
            cache:
              paths:
                - node_modules/**/*
      EnvironmentVariables:
        - Name: REACT_APP_BUCKET_NAME
          Value: !Ref MyS3Bucket
      IAMServiceRole: !GetAtt AmplifyRole.Arn
      Repository: 'https://github.com/your-username/your-repo.git'

  # IAM Role for Amplify
  AmplifyRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service: amplify.amazonaws.com
            Action: 'sts:AssumeRole'
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/AdministratorAccess

Outputs:
  BucketName:
    Description: Name of the S3 bucket
    Value: !Ref MyS3Bucket
  AppName:
    Description: Name of the Amplify app
    Value: !Ref MyAmplifyApp

To deploy this setup across 100 different AWS accounts, you can use AWS Organizations and AWS CloudFormation StackSets.

  1. Create an AWS Organizations structure: Set up your AWS Organizations, including creating the necessary Organizational Units (OUs) to group the 100 AWS accounts.

  2. Create a CloudFormation StackSet: Create a CloudFormation StackSet in the management account of your AWS Organizations. This StackSet will be used to deploy the S3 bucket and Amplify app to the target accounts.

  3. Configure the StackSet parameters: When creating the StackSet, provide the necessary parameters, such as the S3 bucket name and the Amplify app name. You can use parameter references or parameter labels to make the deployment more flexible.

  4. Deploy the StackSet: Deploy the StackSet to the target OUs or accounts within your AWS Organizations. This will create the S3 bucket and Amplify app in each of the 100 AWS accounts.

By using AWS Organizations and CloudFormation StackSets, you can automate the deployment of the S3 bucket and Amplify app across the 100 AWS accounts, ensuring consistency and simplifying the management of the setup.

Remember to update the CloudFormation template with your specific requirements, such as the repository URL for the Amplify app, and to grant the necessary permissions for the Amplify app to access the files in the S3 bucket.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.