删除AWS事件源映射?

时间:2019-01-29 00:38:37

标签: amazon-web-services makefile aws-lambda

所以我有一个make文件,该文件删除了lambda的事件源映射

.PHONY: delete-event-source-mapping
delete-event-source-mappings: ## Delete event source mappings for project lambda.
    aws lambda delete-event-source-mapping \
        --uuid <guid>

但是这被硬编码为单个UUID。如何删除附加到lambda的所有偶数源映射?

1 个答案:

答案 0 :(得分:0)

我最终将目标更改为列出所有事件源映射,并删除列出的所有GUIDS。

.PHONY: delete-event-source-mapping
delete-event-source-mappings: ## Delete event source mappings for project lambda.
    $(eval UUIDS := $(shell aws lambda list-event-source-mappings \
        --function-name <function_name> \
        --event-source <function_arn> | grep "UUID" | awk -F'"' '{print $$4}'))
    for mapping_uuid in $(UUIDS); do \
        aws lambda delete-event-source-mapping --uuid $$mapping_uuid; \
    done

如果要通过其他条件删除(除了仅附加到目标lambda之外),则需要在列表部分之后添加一些解析逻辑。最终,我计划按事件源(例如,来自S3或Kinesis)添加过滤器。