首页 > 解决方案 > 如何通过机器人框架运行 AWS CLI 命令?

问题描述

更新我的问题:我的测试场景是获取特定 S3 存储桶中的文件大小。为此,我安装了 robotframework-aws 库。现在我不确定要使用哪个关键字来获取文件大小。这是我到目前为止编写的代码:

Run AWS CLI Command to capture file size of S3 MRL Hub Source
Create Session With Keys    region: us-east-1    access_key: xxxx   secret_key: xxxx    aws_session_token: str
Read File From S3    bucket_name: com-abc-def-ghi    key: name/of/the/file/i/am/looking/for.parquet

使用此代码,我收到以下错误:

InvalidRegionError: Provided region_name 'region: us-east-1' doesn't match a supported format.

标签: amazon-s3robotframeworkaws-cli

解决方案


您可以使用运行命令,它是OperatingSystem库的一部分,在安装 RobotFramework 时默认已包含该命令。

有了这个,你可以让 Robotframework 运行你想要的任何命令提示符。例如:

*** Settings ***
Library  OperatingSystem

*** Test Cases ***
Test run command
    ${output}=  Run  aws --version
    log  ${output}

当您想要使用aws configure. 我的意思是,你不能指望 Robotframework 测试用例会要求你输入。在这种情况下,您需要事先提供所有aws configure 选项。这意味着您需要profile为您的测试用例准备一个文件,然后您可以连接更多命令,例如:

*** Test Cases ***
Test run command
    ${output}=  Run  aws configure --profile <profilename> && set https_proxy http://webproxy.xyz.com:8080
    log  ${output}

或者更好地使用profiles3 直接使用文件,例如aws s3 ls --profile <profilename>.

请记住,最好的方法是使用某种外部库,例如使用boto3 Python libraryAWSLibrary创建您自己的自定义库。


推荐阅读