WAF list_web_acls works with CLI but returns empty array with Boto3 inside lambda

0

I have some WebACLs in WAF that I want to list from a Lambda function. (I have the Regional WebACL in eu-central-1)

My lambda handler:

def lambda_handler(event, context):    
    waf_client = boto3.client(
        "wafv2",
        aws_access_key_id="SOME_ACCESS_KEY_ID",
        aws_secret_access_key="SOME_SECRET_ACCESS_KEY",
        region_name="eu-central-1"
    )
    
    return waf_client.list_web_acls(Scope="REGIONAL")

Lambda Result:

{
  "WebACLs": [],
  "ResponseMetadata": {...}
}

CLI command that works: aws wafv2 list-web-acls --scope=REGIONAL --region=eu-central-1

Result:

{
    "NextMarker": "something",
    "WebACLs": [
        {
            "Name": "something",
            "Id": "hash1",
            "Description": "",
            "LockToken": "hash2",
            "ARN": "arn:aws:wafv2:eu-central-1:accountid:regional/webacl/something/hash1"
        }
    ]
}


Am I missing something here or the Boto3 WAF client is not behaving as expected?

1개 답변
0
수락된 답변

I can't see a good reason why that doesn't work. Unless the account details you're using at the CLI aren't the same as in the Lambda function. You can use aws sts get-caller-identity and the equivalent boto3 call to confirm.

Note that you don't have to supply credentials within a Lambda function - it's much better practice to create a role which has the right permissions for that Lambda function specifically so that you don't have hard-coded credentials. If you're making cross-account calls then you can do that too.

profile pictureAWS
전문가
답변함 2년 전
  • Removing the credentials resolved the problem as my lambda role already had AWSWAFReadOnlyAccess. Thanks for the swift response!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠