1

I have Python3 script that pulls information from AWS regarding to the AWS Network Firewall Managed Rule Group -

def get_current_version(rule_group_arn):
    response = network_firewall.describe_rule_group_metadata(RuleGroupArn=rule_group_arn)
    return response

print(get_current_version("arn:aws:network-firewall:eu-central-1:aws-managed:stateful-rulegroup/ThreatSignaturesDoSStrictOrder"))

When I execute it, I get response:

{'RuleGroupArn': 'arn:aws:network-firewall:eu-central-1:aws-managed:stateful-rulegroup/ThreatSignaturesDoSStrictOrder', 'RuleGroupName': 'ThreatSignaturesDoSStrictOrder', 'Description': 'Signatures that detect Denial of Service attempts.', 'Type': 'STATEFUL', 'Capacity': 200, 'StatefulRuleOptions': {'RuleOrder': 'STRICT_ORDER'}, 'LastModifiedTime': datetime.datetime(2022, 6, 21, 12, 54, 12, 241000, tzinfo=tzlocal()), 'ResponseMetadata': {'RequestId': 'a4ea84ee-f908-4f2c-9ff1-6b4542b1313c', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': 'a4ea84ee-f908-4f2c-9ff1-6b4542b1313c', 'content-type': 'application/x-amz-json-1.0', 'content-length': '354', 'date': 'Tue, 27 Sep 2022 18:10:26 GMT'}, 'RetryAttempts': 0}}

I want to run similar function in the Lamda, so I wrote this code:

def lambda_handler(event, context):
    response = network_firewall.describe_rule_group_metadata(RuleGroupArn="arn:aws:network-firewall:eu-central-1:aws-managed:stateful-rulegroup/ThreatSignaturesDoSStrictOrder")
    return response

However, response I get is different than previous one, namely one field is missing: LastModifiedTime and this field is crucial for my code's logic.

{
  "RuleGroupArn": "arn:aws:network-firewall:eu-central-1:aws-managed:stateful-rulegroup/ThreatSignaturesDoSStrictOrder",
  "RuleGroupName": "ThreatSignaturesDoSStrictOrder",
  "Description": "Signatures that detect Denial of Service attempts.",
  "Type": "STATEFUL",
  "Capacity": 200,
  "StatefulRuleOptions": {
    "RuleOrder": "STRICT_ORDER"
  },
  "ResponseMetadata": {
    "RequestId": "45bafe6f-8df4-479a-b0bb-c4572dc7f039",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "x-amzn-requestid": "45bafe6f-8df4-479a-b0bb-c4572dc7f039",
      "content-type": "application/x-amz-json-1.0",
      "content-length": "354",
      "date": "Tue, 27 Sep 2022 18:37:07 GMT"
    },
    "RetryAttempts": 0
  }
}

I've read documentation and it states that field should be present. Maybe I'm missing some point.

Thanks in advance for help!

shimo
  • 2,156
  • 4
  • 17
  • 21
elmario-nc
  • 13
  • 3
  • In your first result, the one that contains the `LastModifiedTime`, the value for that key is represented using a `datetime.datetime` object. All of the other fields have values with simple types. In particular, the `date` field is represented in string form. I don't know what this means, but I bet its related to your problem. – CryptoFool Sep 27 '22 at 21:21
  • I agree it is releated, however for different resources (i.e. describe_transit_gateways()) there is also datetime and at first I'm getting error with: TypeError: Object of type datetime is not JSON serializable, but I'm able to overcome this using json.dumps(). However in the mentioned case, there is no error, just field LastModifiedTime does not appear in the output, like it does not exist. – elmario-nc Sep 27 '22 at 21:44

1 Answers1

0

This problem is from the version of boto3 in the Lambda function.

The default version of boto3 for Python3.7 to 3.9 is boto3-1.20.32 botocore-1.23.32 (doc)

We cannot find the dict item like LastModifiedTime in the version of boto3. There is no such response for that version.

This so answer might help to upgrade boto3.

shimo
  • 2,156
  • 4
  • 17
  • 21