Using the AWS CLI (reference)

Using the AWS CLI (reference)

  1. Create a VPC and configure its settings such as the CIDR block, subnets, security groups, and routing tables using the following command:
aws ec2 create-vpc --cidr-block <CIDR_BLOCK>
aws ec2 create-subnet --vpc-id <VPC_ID> --cidr-block <CIDR_BLOCK>
aws ec2 create-security-group --group-name <GROUP_NAME> --description <DESCRIPTION>
aws ec2 authorize-security-group-ingress --group-id <GROUP_ID> --protocol <PROTOCOL> --port <PORT> --cidr-ip <CIDR_IP>
  1. Create an EC2 instance with Windows Server and configure its settings such as instance type, storage, and network settings using the following command:
aws ec2 run-instances --image-id <IMAGE_ID> --instance-type <INSTANCE_TYPE> --subnet-id <SUBNET_ID> --security-group-ids <GROUP_ID>
  1. Connect to the EC2 instance using Remote Desktop Protocol (RDP) and install the necessary software and updates.

  2. Create an FSx for Windows file system and configure its settings such as the file system size, backup settings, and performance settings using the following command:

aws fsx create-file-system --storage-capacity <STORAGE_CAPACITY> --file-system-type <FILE_SYSTEM_TYPE> --subnet-ids <SUBNET_ID>
  1. Map the EC2 instance to the FSx file system using the appropriate drive letter and assign it proper permissions and access controls.

  2. Create a Microsoft AD and configure its settings such as the domain name and subnets using the following command:

aws directoryservice create-microsoft-ad --name <NAME> --password <PASSWORD> --vpc-settings VpcId=<VPC_ID>,SubnetIds=<SUBNET_ID>
  1. Map the EC2 instance to the Microsoft AD using the following command:
net ads join -U <ADMIN_NAME>%<PASSWORD>
  1. Create a CloudWatch dashboard to monitor the performance and utilization of the FSx file system using the following command:
aws cloudwatch put-dashboard --dashboard-name <DASHBOARD_NAME> --dashboard-body <DASHBOARD_BODY>
  1. Set up backup and disaster recovery options for the FSx file system, such as creating snapshots and replicating data to other regions using the following command:
aws fsx create-backup --file-system-id <FILE_SYSTEM_ID>
  1. Create IAM roles and policies to control access to the FSx file system and EC2 instance using the following command:
aws iam create-role --role-name fsx-access --assume-role-policy-document file://trust-policy.json

where trust-policy.json is a file that contains the trust relationship policy for the IAM role. The policy should specify the EC2 service as the trusted entity and allow it to assume the role.

Next, create a policy that allows the IAM role to access the FSx file system using the following command:

aws iam create-policy --policy-name fsx-policy --policy-document file://permission-policy.json

where permission-policy.json is a file that contains the permissions policy for the IAM role. The policy should specify the actions that are allowed on the FSx file system, such as CreateFileSystem, DescribeFileSystems, and DeleteFileSystem.

Finally, attach the policy to the IAM role using the following command:

aws iam attach-role-policy --role-name fsx-access --policy-arn arn:aws:iam::<account-id>:policy/fsx-policy

where account-id is your AWS account ID.

  1. Associate the IAM role with the EC2 instance using the following command:
aws ec2 associate-iam-instance-profile --instance-id <instance-id> --iam-instance-profile Name=fsx-access

where instance-id is the ID of the EC2 instance that you launched earlier. This command will allow the EC2 instance to use the IAM role and access the FSx file system.

  1. Mount the FSx file system on the EC2 instance using the following command:
mount -t cifs //<file-system-id>.<dns-name>.fsx.aws.<region>.amazonaws.com/<share-name> <mount-point> -o vers=3.0,username=<fsx-user>,password=<fsx-password>

where file-system-id is the ID of the FSx file system, dns-name is the DNS name of the FSx file system, region is the AWS region where the FSx file system is located, share-name is the name of the share that you created earlier, mount-point is the local path on the EC2 instance where you want to mount the FSx file system, fsx-user is the user name for accessing the FSx file system, and fsx-password is the password for accessing the FSx file system. This command will allow you to access the files and folders on the FSx file system from the EC2 instance.

  1. Map the EC2 instance to the Microsoft AD using the following command:
net ads join -U <administrator>

where administrator is the user name of an administrator in the Microsoft AD. This command will allow the EC2 instance to join the Microsoft AD, which will enable you to use the EC2 instance as a file server for the AD environment.

  1. Share the FSx file system using the following command:
net share <share-name>=<mount-point> /grant:<user-group>,full

where share-name is the name of the share that you want to create, mount-point is the path to the mounted FSx file system, and user-group is the name of a user group in the Microsoft AD that you want to grant access to the share. This command will create a share on the EC2 instance and grant access to the specified user group.

  1. Verify the share by accessing it from a Windows client in the same Microsoft AD. This will confirm that the EC2 instance is correctly joined to the Microsoft AD and is able to share files from the FSx file system.

  2. Set up the EC2 instance as a preferred file server using the following command:

aws fsx create-preferred-file-server --file-system-id <file-system-id> --windows-configuration-id <windows-configuration-id>

where file-system-id is the ID of the FSx file system and windows-configuration-id is the ID of the Windows configuration for the EC2 instance. This command will set the EC2 instance as the preferred file server for the FSx file system, which will ensure that clients will connect to this instance for file access when it’s available.

  1. Set up the EC2 instance as a standby file server using the following command:
aws fsx create-standby-file-server --file-system-id <file-system-id> --windows-configuration-id <windows-configuration-id>

where file-system-id is the ID of the FSx file system and windows-configuration-id is the ID of the Windows configuration for the EC2 instance. This command will set the EC2 instance as the standby file server for the FSx file system, which will ensure that clients will connect to this instance as a backup when the preferred file server is unavailable.

  1. Verify the file server configuration by accessing the share from a Windows client in the Microsoft AD. Confirm that clients are connecting to the EC2 instance as the preferred or standby file server as expected.

  2. Repeat steps 7 to 18 for each additional EC2 instance you want to use with the FSx file system to set up a high-availability file server architecture using AWS CLI.

  3. Monitor the FSx file system performance, availability, and utilization using the AWS CloudWatch service, and troubleshoot any issues as needed. You can use the following command to view CloudWatch metrics:

aws cloudwatch get-metric-data
  1. Schedule regular backups of the FSx file system to ensure data availability and recoverability in case of failures or data loss. You can use the following command to create a backup:
aws fsx create-backup
  1. Finally, regularly review and update the IAM policies and roles associated with the EC2 instances and FSx file system to ensure secure and controlled access. You can use the following command to update an IAM policy:
aws iam update-policy