|
| 1 | +# EC2 User data scripts |
| 2 | + |
| 3 | +## Introduction |
| 4 | +These sample scripts provide a way to launch an AWS EC2 instance with `user data` that will create an FSxN |
| 5 | +volume and LUN, mount it to the instance, while installing all the needed libraries and resources. |
| 6 | + |
| 7 | +## Notes |
| 8 | +- LUN size will be set to 90% of the volume size, the remain space is needed for the the LUN managment operation. |
| 9 | + This means that usuable volume size is 90% of the requestd size. |
| 10 | +- The process might take several minutes to be compleetd. |
| 11 | + |
| 12 | +## Set Up |
| 13 | +1. Create an AWS SecretsManager secret to hold the password of the account you plan to use to authenicate to the FSxN file system with. |
| 14 | +The secret should be of type `other` with value set to `Plain Text` that holds just the password. |
| 15 | +2. Create an AWS IAM role that has EC2 as the trusted entity and has permissions to read the secret value. Here is an example policy that will do that: |
| 16 | + ```json |
| 17 | + { |
| 18 | + "Version": "2012-10-17", |
| 19 | + "Statement": [ |
| 20 | + { |
| 21 | + "Sid": "VisualEditor0", |
| 22 | + "Effect": "Allow", |
| 23 | + "Action": [ |
| 24 | + "secretsmanager:GetSecretValue" |
| 25 | + ], |
| 26 | + "Resource": "arn:aws:secretsmanager:us-west-2:999999999:secret:fsxn-password-75WJ57" |
| 27 | + } |
| 28 | + ] |
| 29 | + } |
| 30 | + ``` |
| 31 | + Replace the "Resource" ARN with the ARN of your secret. |
| 32 | + |
| 33 | +3. Download the needed script according to the instance type you want to run (Linux or Windows). |
| 34 | + |
| 35 | + For the Linux version of the script, set the following values at the top of it: |
| 36 | + - SECRET_NAME - Secret name has has the password for the `ONTAP-USER`. |
| 37 | + - AWS_REGION - AWS secret manager region. |
| 38 | + - FSXN_ADMIN_IP - IP address, or hostname, of the FSxN management endpoint. |
| 39 | + - VOLUME_NAME - The name of the volume you want to create in your FSxN. |
| 40 | + - VOLUME_SIZE - The size of the volume you want to create in GB e.g [100g] |
| 41 | + - SVM_NAME - The name of the SVM where the volume is to be created. |
| 42 | + - ONTAP_USER - The ONTAP user id you wish to authenicate with. |
| 43 | + |
| 44 | + For the Windows version of the script, set the following values at the top of it: |
| 45 | + - $secretId - secret ARN that holds the password for the `$user`. |
| 46 | + - $ip - IP address, or hostname, of the FSxN management endpoint. |
| 47 | + - $volName - The name of the volume you want to create in your FSxN. |
| 48 | + - $volSize - The size of the volume you want to create in GB e.g [100] |
| 49 | + - $drive_letter - The drive letter to assign to the volume. |
| 50 | + - $user - The ONTAP user id you wish to authenicate with. |
| 51 | + - $svm_name - The name of the SVM where the volume is to be created. |
| 52 | + |
| 53 | +4. Save the script file. |
| 54 | + |
| 55 | +## On AWS console EC2 |
| 56 | + |
| 57 | +### For Linux installation: |
| 58 | +<ol> |
| 59 | + <li>Launch new instance |
| 60 | + <ol> |
| 61 | + <li>Fill in the server name.</li> |
| 62 | + <li>Select 'Amazon Linux'.</li> |
| 63 | + <li>Under Amazon Machine Image select 'Amazon Linux 2023 AMI'.</li> |
| 64 | + <li>Fill in the other settings based on your networking and business needs.</li> |
| 65 | + <li>Under 'Advanced details': |
| 66 | + <ol> |
| 67 | + <li>Set the 'IAM instance profile' to the policy you created in the steps above.</li> |
| 68 | + <li>At the bottom, under the 'User data' section, press 'choose file' and select the script saved above.</li> |
| 69 | + </ol> |
| 70 | + </li> |
| 71 | + </ol> |
| 72 | + </li> |
| 73 | + <li>Launch the instance.</li> |
| 74 | +</ol> |
| 75 | + |
| 76 | +The installation log file can be found at: `/home/ec2-user/install.log`. |
| 77 | +If an error occurs while the installation is running, the script will terminate and all installations and setup will roll back. |
| 78 | + |
| 79 | +### For Windows installation: |
| 80 | +<ol> |
| 81 | + <li>Launch new instance |
| 82 | + <ol> |
| 83 | + <li>Fill in the server name.</li> |
| 84 | + <li>Select 'Windows'.</li> |
| 85 | + <li>Under Amazon Machine Image select 'Windows Server 2025 Base'.</li> |
| 86 | + <li>Fill in any other setting based on your networking and business needs.</li> |
| 87 | + <li>Under the 'Advanced details': |
| 88 | + <ol> |
| 89 | + <li>Set the 'IAM instance profile' to the role you created in the steps above.</li> |
| 90 | + <li>At the bottom, under the 'User data' section, press 'choose file', and select the script saved above.</li> |
| 91 | + </ol> |
| 92 | + </li> |
| 93 | + </ol> |
| 94 | + </li> |
| 95 | + <li>Launch the instance.</li> |
| 96 | +</ol> |
| 97 | + |
| 98 | +The installation log file can be found at: `C:\Users\Administrator\install.log`. |
| 99 | +If an error occurs while the installation is running, a message will be inserted into the installation log file, it will attempt to roll back any work that it preformed, finally the script will terminate. |
| 100 | + |
| 101 | +**Note:** It can take 20 to 30 minutes for the script to compplete. Check the installation log file to confirm it is done. The line `Uninstall script removed` should be at the bottom of the file when the script has finished. |
0 commit comments