AWS Config 通知的正确格式是怎样的?
来源:stackoverflow
时间:2024-03-08 11:00:26 376浏览 收藏
在Golang实战开发的过程中,我们经常会遇到一些这样那样的问题,然后要卡好半天,等问题解决了才发现原来一些细节知识点还是没有掌握好。今天golang学习网就整理分享《AWS Config 通知的正确格式是怎样的?》,聊聊,希望可以帮助到正在努力赚钱的你。
我对 Go 还很陌生,我必须使用 aws go sdk 来读取来自 SQS 的 AWS Config 通知。 (AWS 配置服务 -> sns -> sqs) 我能够收到消息。但我想进入消息获取资源类型、资源Id、awsRegion 等信息。 这是我的示例消息字符串(字符串化的 json)。 https://gist.github.com/HarishAtGitHub/fcbb01515d11044d04bde14a3d9f6e7a
我有Python背景,在Python中这很容易做到,因为json就像一本字典。我们可以通过嵌套索引轻松获取它。 但在 go 中,我似乎应该使用正确的结构来理解此消息。
有人可以向我指出正确的结构或有关如何获取消息中不同属性的任何想法吗?
解决方案
我总是使用 this 工具从 json blob 生成结构定义。您自己需要做的唯一一件事就是为 null 值选择一个类型:它显然无法确定这些值,因此将它们设置为 interface{} (任何类型都可以实现此功能)。
如果您只想解组,则可以省略结构标记(例如 json:"changetype"),而不是相反。
type ConfigNotification struct {
ConfigurationItemDiff struct {
ChangedProperties struct {
} `json:"changedProperties"`
ChangeType string `json:"changeType"`
} `json:"configurationItemDiff"`
ConfigurationItem struct {
RelatedEvents []interface{} `json:"relatedEvents"`
Relationships []interface{} `json:"relationships"`
Configuration struct {
Attachments []interface{} `json:"attachments"`
AvailabilityZone string `json:"availabilityZone"`
CreateTime time.Time `json:"createTime"`
Encrypted bool `json:"encrypted"`
KmsKeyID interface{} `json:"kmsKeyId"`
Size int `json:"size"`
SnapshotID string `json:"snapshotId"`
State string `json:"state"`
VolumeID string `json:"volumeId"`
Iops int `json:"iops"`
Tags []struct {
Key string `json:"key"`
Value string `json:"value"`
} `json:"tags"`
VolumeType string `json:"volumeType"`
} `json:"configuration"`
SupplementaryConfiguration struct {
} `json:"supplementaryConfiguration"`
Tags struct {
Creator string `json:"creator"`
} `json:"tags"`
ConfigurationItemVersion string `json:"configurationItemVersion"`
ConfigurationItemCaptureTime time.Time `json:"configurationItemCaptureTime"`
ConfigurationStateID int64 `json:"configurationStateId"`
AwsAccountID string `json:"awsAccountId"`
ConfigurationItemStatus string `json:"configurationItemStatus"`
ResourceType string `json:"resourceType"`
ResourceID string `json:"resourceId"`
ResourceName interface{} `json:"resourceName"`
ARN string `json:"ARN"`
AwsRegion string `json:"awsRegion"`
AvailabilityZone string `json:"availabilityZone"`
ConfigurationStateMd5Hash string `json:"configurationStateMd5Hash"`
ResourceCreationTime time.Time `json:"resourceCreationTime"`
} `json:"configurationItem"`
NotificationCreationTime time.Time `json:"notificationCreationTime"`
MessageType string `json:"messageType"`
RecordVersion string `json:"recordVersion"`
}文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《AWS Config 通知的正确格式是怎样的?》文章吧,也可关注golang学习网公众号了解相关技术文章。
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
Golang · Go问答 | 9小时前 | 并发 · channel · select · 性能排查 · Go问答 · select Go channel context default CPU飙高 忙等循环 ticker438 收藏
-
Golang · Go问答 | 10小时前 | pprof · trace · 性能排查 · Go问答 · 服务安全 · Go pprof 生产环境 trace 安全入口 net/http/pprof 性能排障349 收藏
-
Golang · Go问答 | 11小时前 | channel · 并发编程 · Go问答 · 背压 · 容量规划 · Goroutine channel 缓冲区 背压 Go问答 buffered channel 并发容量377 收藏
-
Golang · Go问答 | 11小时前 | interface · 单元测试 · 架构设计 · repository · Go问答 · 单元测试 架构设计 interface 接口设计 Go问答 调用方定义 Repository212 收藏
-
Golang · Go问答 | 11小时前 | JSON · time.Time · 接口设计 · Go问答 · encoding/json · encoding/json API响应 JSON序列化 time.Time omitempty Go问答 omitzero315 收藏
-
Golang · Go问答 | 12小时前 | HTTP · Cookie · 浏览器 · cors · Go问答 · SameSite · cookie cors Secure SameSite Go问答 Set-Cookie 跨站请求 credentials246 收藏
-
Golang · Go问答 | 12小时前 | 中间件 · Context · Go问答 · 架构模式 · 代码边界 · 中间件 context Context.Value Go问答 WithValue 请求作用域 业务参数269 收藏
-
Golang · Go问答 | 12小时前 | JSON · 后端开发 · Go问答 · encoding/json · 接口解析 · JSON解析 encoding/json DisallowUnknownFields Go问答 RawMessage json.Decoder UseNumber151 收藏
-
Golang · Go问答 | 1天前 | HTTP · net/http · Go问答 · 流式响应 · ResponseController · net/http FLUSH 流式响应 Go问答 ResponseController FullDuplex 写超时161 收藏
-
Golang · Go问答 | 1天前 | HTTP · sse · Go问答 · 用户体验 · 流式响应 · Go EventSource SSE Go问答 Server-Sent Events 长任务进度 http.Flusher293 收藏
-
Golang · Go问答 | 1天前 | Timer · 性能优化 · time.After · Go问答 · Go 内存优化 Timer time.After Go问答 time.NewTimer Go1.23384 收藏
-
Golang · Go问答 | 1天前 | go · Context · 并发编程 · 接口超时 · 超时控制 goroutine泄漏 WithTimeout Go context Go问答 CancelFunc477 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 516次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 500次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 485次学习