Skip to content

Commit 06b2212

Browse files
authored
Merge branch 'main' into add_wait
2 parents cef3f4c + 9c8941d commit 06b2212

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

Management-Utilities/auto_set_fsxn_auto_grow/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The Lambda function doesn't leverage that many AWS services, so only a few permi
2727
| Allow:logs:CreateLogGroup | arn:aws:logs:<LAMBDA_REGION>:<ACCOUNT_ID>:* | This is required so you can get logs from the Lambda function. |
2828
| Allow:logs:CreateLogStream<BR>Allow:logs:PutLogEvents | arn:aws:logs:<LAMBDA_REGION>:<ACCOUNT_ID>:/aws/lambda/<LAMBDA_FUNCTION_NAME>:* | This is required so you can get logs from the Lambda function. |
2929
| Allow:secretsmanager:GetSecretValue | <ARN_OF_SECRET_WITHIN_SECRETS_MANAGER> | This is required so the Lambda function can get the credentials for the FSxN file system. |
30+
| Allow:dynamodb:Scan | <ARN_OF_DYNAMODB_TABLE> | This is optional, depending on if you put your secretsTable in a DynamoDB. |
3031
| Allow:fsx:DescribeFileSystems<BR>Allow:fsx:DescribeVolumes | * | You can't limit these API. They are required to get information regarding the file system and volumes. |
3132
| Allow:ec2:CreateNetworkInterface<BR>Allow:ec2:DeleteNetworkInterface<BR>Allow:ec2:DescribeNetworkInterfaces | * | Since the Lambda function is going to run within your VPC, it has to be able to create a network interface to communicate with the FSxn file system API. |
3233

@@ -40,6 +41,7 @@ FSxN file system is attached to.
4041

4142
- FSx
4243
- SecretsManager
44+
- DynamoDB - You only need this one if you are going to store you secrtsTable in DynamoDB. It can be a Gateway endpoint.
4345

4446
### Create the Lambda Function
4547
Create a Lambda function with the following parameters:
@@ -60,6 +62,12 @@ is a dictionary with the following keys:
6062
- secretName - The name of the secret in Secrets Manager.
6163
- usernameKey - The name of the key in the secret that contains the username.
6264
- passwordKey - The name of the key in the secret that contains the password.
65+
66+
**NOTE:** Instead of defining the secretsTable in the script, you can define
67+
dynamodbSecretsTableName and dynamodbRegion and the script will read in the
68+
secretsTable information from the specified DynamoDB table. The table should have
69+
the same fields as the secretsTable defined above.
70+
6371
- secretsManagerRegion - Defines the region where your secrets are stored.
6472
- autoSizeMode - Defines the auto size mode you want to set the volume to. Valid values are:
6573
- grow - The volume will automatically grow when it reaches the grow threshold.

Management-Utilities/auto_set_fsxn_auto_grow/set_fsxn_volume_auto_grow.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,21 @@
3333
# a different secret and/or keys for the username and password for each
3434
# of the FSxId.
3535
secretsTable = [
36-
{"id": "fs-0e8d9172fa5XXXXXX", "secretName": "fsxn-credentials", "usernameKey": "fsxn-username", "passwordKey": "fsxn-password"},
37-
{"id": "fs-020de2687bdXXXXXX", "secretName": "fsxn-credentials", "usernameKey": "fsxn-username", "passwordKey": "fsxn-password"},
38-
{"id": "fs-07bcb7ad84aXXXXXX", "secretName": "fsxn-credentials", "usernameKey": "fsxn-username", "passwordKey": "fsxn-password"},
39-
{"id": "fs-077b5ff4195XXXXXX", "secretName": "fsxn-credentials", "usernameKey": "fsxn-username", "passwordKey": "fsxn-password"}
36+
{"fsxId": "fs-0e8d9172fa5XXXXXX", "secretName": "fsxn-credentials", "usernameKey": "fsxn-username", "passwordKey": "fsxn-password"},
37+
{"fsxId": "fs-020de2687bdXXXXXX", "secretName": "fsxn-credentials", "usernameKey": "fsxn-username", "passwordKey": "fsxn-password"},
38+
{"fsxId": "fs-07bcb7ad84aXXXXXX", "secretName": "fsxn-credentials", "usernameKey": "fsxn-username", "passwordKey": "fsxn-password"},
39+
{"fsxId": "fs-077b5ff4195XXXXXX", "secretName": "fsxn-credentials", "usernameKey": "fsxn-username", "passwordKey": "fsxn-password"}
4040
]
4141
#
42+
# If you don't want to define the secretsTable in this script, you can
43+
# define the following variables to use a DynamoDB table to get the
44+
# secret information.
45+
#
46+
# NOTE: If both the secretsTable, and dynamodbSecretsTableName are defined,
47+
# then the secretsTable will be used.
48+
#dynamodbRegion="us-west-2"
49+
#dynamodbSecretsTableName="fsx_secrets"
50+
#
4251
# Set the region where the secrets are stored.
4352
secretsManagerRegion="us-west-2"
4453
#
@@ -77,9 +86,10 @@
7786
# find the credentials.
7887
################################################################################
7988
def getCredentials(secretsManagerClient, fsxnId):
89+
global secretsTable
8090

8191
for secretItem in secretsTable:
82-
if secretItem['id'] == fsxnId:
92+
if secretItem['fsxId'] == fsxnId:
8393
secretsInfo = secretsManagerClient.get_secret_value(SecretId=secretItem['secretName'])
8494
secrets = json.loads(secretsInfo['SecretString'])
8595
username = secrets[secretItem['usernameKey']]
@@ -113,7 +123,7 @@ def getVolumeData(fsxClient, volumeId, volumeARN):
113123
################################################################################
114124
def lambda_handler(event, context):
115125

116-
global logger
126+
global logger, secretsTable
117127
#
118128
# Set up "logging" to appropriately display messages. It can be set it up
119129
# to send messages to a syslog server.
@@ -138,6 +148,19 @@ def lambda_handler(event, context):
138148
retries = Retry(total=None, connect=1, read=1, redirect=10, status=0, other=0) # pylint: disable=E1123
139149
http = urllib3.PoolManager(cert_reqs='CERT_NONE', retries=retries)
140150
#
151+
# Read in the secretTable if it is not already defined.
152+
if 'dynamodbRegion' in globals():
153+
dynamodbClient = boto3.resource("dynamodb", region_name=dynamodbRegion) # pylint: disable=E0602
154+
155+
if 'secretsTable' not in globals():
156+
if 'dynamodbRegion' not in globals() or 'dynamodbSecretsTableName' not in globals():
157+
raise Exception('Error, you must either define the secretsTable array at the top of this script, or define dynamodbRegion and dynamodbSecretsTableName.')
158+
159+
table = dynamodbClient.Table(dynamodbSecretsTableName) # pylint: disable=E0602
160+
161+
response = table.scan()
162+
secretsTable = response["Items"]
163+
#
141164
# Get the FSxN ID, region, volume name, volume ID, and volume ARN from the CloudWatch event.
142165
fsxId = event['detail']['responseElements']['volume']['fileSystemId']
143166
regionName = event['detail']['awsRegion']

0 commit comments

Comments
 (0)