配置单个aws cli操作以调用api网关方法的插件

awscli-plugin-execute-api的Python项目详细描述


awscli插件执行api

配置单个aws cli操作以调用api网关/lambda方法的插件

快速启动

使用pip

安装
$ pip install awscli-plugin-execute-api

如果您在自制程序中安装了awscli,请使用其捆绑的python:

$ /usr/local/opt/awscli/libexec/bin/pip install awscli-plugin-execute-api

注册插件

$ aws configure set plugins.execute-api awscli_plugin_execute_api

配置操作终结点

首先使用execute-api:Invoke权限为iam配置配置文件:

$ exportAWS_PROFILE=myprofile

$ aws configure
AWS Access Key ID [None]: AKIA...
AWS Secret Access Key [None]: pWim...
Default region name [None]: us-east-1
Default output format [None]: json

接下来,为操作及其api网关调用url配置插件:

$ aws configure set dynamodb.update-table https://m303r7o808.execute-api.us-east-1.amazonaws.com/Prod/update-table
<详细信息>您可以查看或手动配置`$home/.aws/config`…
[plugins]
execute-api = awscli_plugin_execute_api

[profile myprofile]
region = us-east-1
output = json
dynamodb =
    update-table = https://m303r7o808.execute-api.us-east-1.amazonaws.com/Prod/update-table

运行操作

现在运行命令:

$ aws dynamodb update-table --table-name $TABLE_NAME --sse-specification Enabled=false
An error occurred (ValidationException) when calling the UpdateTable operation: Custom error from Lambda handler
<详细信息>您可以使用“--debug”标志来验证端点…
$ aws dynamodb update-table --debug --table-name $TABLE_NAME
Plugin awscli_plugin_execute_api: Config [myprofile] dynamodb.update-table => URL https://m303r7o808.execute-api.us-east-1.amazonaws.com/Prod/update-table
Plugin awscli_plugin_execute_api: renamed X-Amz-Target DynamoDB_20120810.UpdateTable

$ aws dynamodb describe-table --debug --table-name $TABLE_NAME
Plugin awscli_plugin_execute_api: Config [myprofile] dynamodb.describe-table not found

动机

出于安全原因,我们希望让iam用户访问aws api调用功能的limited subset。例如,在dynamodb update-table操作中,我们希望允许用户修改:

  • 全局索引

但不允许他们修改:

  • 提供的吞吐量
  • 服务器端加密

“无服务器”解决方案包括:

  • IAM用户

    • 禁止dynamodb:UpdateTable
    • 允许在API网关资源上execute-api:Invoke的策略
    • 访问键
  • API网关方法

    • 发送update-table请求的URL
    • AWS U IAM授权
  • lambda函数

    • 允许dynamodb:UpdateTable
    • 验证并执行update-table请求的代码
  • aws cli

    • dynamodb update-table命令的自定义终结点url
    • API网关的请求签名

此插件为单个cli操作注册一个url并自动使用它。

$ aws configure set dynamodb.update-table https://m303r7o808.execute-api.us-east-1.amazonaws.com/Prod/update-table
$ aws dynamodb update-table --table-name $TABLE_NAME --sse-specification Enabled=false
An error occurred (ValidationException) when calling the UpdateTable operation: Modifying SSESpecification is not allowed

故障排除

IAM

cli用户需要API execution permissions

{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["execute-api:Invoke"],"Resource":["arn:aws:execute-api:us-east-1:303718836660:m303r7o808/*/POST/update-table"]}]}

lambda

cli操作位于X-Target头中,因为X-Amz-Target

学分

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
不能找出错误吗?(爪哇)   java Vaadin 7:有没有办法让Vaadin注意到标签是否溢出?   java从多行文本视图中获取特定行   java上载对象到内容长度为的Google Firebase云存储   Liferay 6.2中的java无法将对象从类传递到jsp   java使用JasperReports导出到Excel:如何为列添加自动筛选   java Explain警告:对varargs方法的非arargs调用,最后一个参数的参数类型不精确   为什么java在我的道路上,而不是javac?   java在意图中传递id时显示异常   java正在访问另一个类的属性   使用文件流的java   java在Spring组件之间共享信息   从未使用java专用字段“SerialVersionId”:intelliJ   java在执行maven命令期间获取FileNotFoundException   spring boot应用程序在cloud foundry java上崩溃。非法国家例外