-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws.go
144 lines (133 loc) · 6.17 KB
/
aws.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package external
import (
"context"
"time"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/account"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/costexplorer"
)
func GetIconURL(service string) string {
switch service {
case "AWS Cost Explorer":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/CloudFinancialManagement/CostExplorer.png?raw=true"
case "AWS Key Management Service":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/SecurityIdentityCompliance/KeyManagementService.png?raw=true"
case "AWS Lambda":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Compute/Lambda.png?raw=true"
case "AWS X-Ray":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/DeveloperTools/XRay.png?raw=true"
case "Amazon API Gateway":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/ApplicationIntegration/APIGateway.png?raw=true"
case "Amazon Simple Email Service":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/BusinessApplications/SimpleEmailService.png?raw=true"
case "Amazon DynamoDB":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Database/DynamoDB.png?raw=true"
case "Amazon EC2 Container Registry (ECR)", "Amazon Elastic Container Registry Public":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Containers/ElasticContainerRegistry.png?raw=true"
case "Amazon Elastic Container Service":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Containers/ElasticContainerService.png?raw=true"
case "Amazon Elastic Load Balancing":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/NetworkingContentDelivery/ElasticLoadBalancingApplicationLoadBalancer.png?raw=true"
case "Amazon Relational Database Service":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Database/Aurora.png?raw=true"
case "Amazon Route 53":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/NetworkingContentDelivery/Route53.png?raw=true"
case "Amazon Simple Storage Service":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Storage/SimpleStorageService.png?raw=true"
case "AmazonCloudWatch":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/ManagementGovernance/CloudWatch.png?raw=true"
case "Amazon CloudFront":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/NetworkingContentDelivery/CloudFront.png?raw=true"
case "AWS Amplify":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/FrontEndWebMobile/AmplifyAWSAmplifyStudio.png?raw=true"
case "AWS Glue":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Analytics/Glue.png?raw=true"
case "Amazon Simple Notification Service":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/ApplicationIntegration/SimpleNotificationService.png?raw=true"
case "AWS Secrets Manager":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/SecurityIdentityCompliance/SecretsManager.png?raw=true"
case "Amazon Virtual Private Cloud":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Groups/VPC.png?raw=true"
case "AWS WAF":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/SecurityIdentityCompliance/WAF.png?raw=true"
case "EC2 - Other":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Compute/EC2.png?raw=true"
case "AWS Step Functions":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/ApplicationIntegration/StepFunctions.png?raw=true"
case "Amazon Elastic Compute Cloud - Compute":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Compute/EC2.png?raw=true"
case "AWS CloudTrail":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/ManagementGovernance/CloudTrail.png?raw=true"
case "Amazon Simple Queue Service":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/ApplicationIntegration/SimpleQueueService.png?raw=true"
case "Amazon GuardDuty":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/SecurityIdentityCompliance/GuardDuty.png?raw=true"
case "Amazon Elastic Container Service for Kubernetes":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/Containers/EKSCloud.png?raw=true"
case "Amazon Cognito":
return "https://github.com/awslabs/aws-icons-for-plantuml/blob/main/dist/SecurityIdentityCompliance/Cognito.png?raw=true"
case "Tax":
return ""
default:
return ""
}
}
func GetCost() (*costexplorer.GetCostAndUsageOutput, error) {
now := time.Now()
end := now.Format("2006-01-02")
twoDaysBefore := now.AddDate(0, 0, -3).Format("2006-01-02")
granularity := "DAILY"
metrics := []string{
"AmortizedCost",
"BlendedCost",
"UnblendedCost",
"UsageQuantity",
}
sess, err := session.NewSession(&aws.Config{
Region: aws.String("us-east-1")},
)
if err != nil {
return nil, err
}
svc := costexplorer.New(sess)
result, err := svc.GetCostAndUsage(&costexplorer.GetCostAndUsageInput{
TimePeriod: &costexplorer.DateInterval{
Start: aws.String(twoDaysBefore),
End: aws.String(end),
},
Granularity: aws.String(granularity),
GroupBy: []*costexplorer.GroupDefinition{
{
Type: aws.String("DIMENSION"),
Key: aws.String("SERVICE"),
},
},
Metrics: aws.StringSlice(metrics),
Filter: &costexplorer.Expression{
Not: &costexplorer.Expression{
Dimensions: &costexplorer.DimensionValues{
Key: aws.String("RECORD_TYPE"),
Values: aws.StringSlice([]string{"Credit"}),
},
},
},
})
if err != nil {
return nil, err
}
return result, nil
}
func GetAccountFullName(ctx context.Context) (string, error) {
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
return "", err
}
client := account.NewFromConfig(cfg)
output, err := client.GetContactInformation(ctx, &account.GetContactInformationInput{})
if err != nil {
return "", err
}
return *output.ContactInformation.FullName, nil
}