Skip to content

Commit 7745ce7

Browse files
misravedCopilotParthaI
authored
Add aws_ses_template table (#2480)
Co-authored-by: Copilot <[email protected]> Co-authored-by: Keep Focused <[email protected]>
1 parent 56d3f3a commit 7745ce7

File tree

3 files changed

+301
-0
lines changed

3 files changed

+301
-0
lines changed

aws/plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
518518
"aws_servicequotas_service_quota_change_request": tableAwsServiceQuotasServiceQuotaChangeRequest(ctx),
519519
"aws_ses_domain_identity": tableAwsSESDomainIdentity(ctx),
520520
"aws_ses_email_identity": tableAwsSESEmailIdentity(ctx),
521+
"aws_ses_template": tableAwsSESTemplate(ctx),
521522
"aws_sfn_state_machine": tableAwsStepFunctionsStateMachine(ctx),
522523
"aws_sfn_state_machine_execution": tableAwsStepFunctionsStateMachineExecution(ctx),
523524
"aws_sfn_state_machine_execution_history": tableAwsStepFunctionsStateMachineExecutionHistory(ctx),

aws/table_aws_ses_template.go

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
package aws
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/ses"
7+
"github.com/aws/aws-sdk-go-v2/service/ses/types"
8+
9+
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
10+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
11+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
12+
)
13+
14+
func tableAwsSESTemplate(_ context.Context) *plugin.Table {
15+
return &plugin.Table{
16+
Name: "aws_ses_template",
17+
Description: "AWS SES Template",
18+
List: &plugin.ListConfig{
19+
Hydrate: listSESTemplates,
20+
KeyColumns: []*plugin.KeyColumn{
21+
{
22+
Name: "name",
23+
Require: plugin.Optional,
24+
},
25+
},
26+
Tags: map[string]string{"service": "ses", "action": "ListTemplates"},
27+
},
28+
HydrateConfig: []plugin.HydrateConfig{
29+
{
30+
Func: getSESTemplateDetails,
31+
Tags: map[string]string{"service": "ses", "action": "GetTemplate"},
32+
},
33+
},
34+
GetMatrixItemFunc: SupportedRegionMatrix(AWS_EMAIL_SERVICE_ID),
35+
Columns: awsRegionalColumns([]*plugin.Column{
36+
{
37+
Name: "name",
38+
Description: "The name of the template.",
39+
Type: proto.ColumnType_STRING,
40+
},
41+
{
42+
Name: "subject_part",
43+
Description: "The subject line of the email.",
44+
Type: proto.ColumnType_STRING,
45+
Hydrate: getSESTemplateDetails,
46+
},
47+
{
48+
Name: "text_part",
49+
Description: "The email body that will be visible to recipients whose email clients do not display HTML.",
50+
Type: proto.ColumnType_STRING,
51+
Hydrate: getSESTemplateDetails,
52+
},
53+
{
54+
Name: "html_part",
55+
Description: "The HTML body of the email.",
56+
Type: proto.ColumnType_STRING,
57+
Hydrate: getSESTemplateDetails,
58+
},
59+
{
60+
Name: "created_timestamp",
61+
Description: "The time and date the template was created.",
62+
Type: proto.ColumnType_TIMESTAMP,
63+
},
64+
65+
// Standard columns for all tables
66+
{
67+
Name: "title",
68+
Description: resourceInterfaceDescription("title"),
69+
Type: proto.ColumnType_STRING,
70+
Transform: transform.FromField("Name"),
71+
},
72+
}),
73+
}
74+
}
75+
76+
//// LIST FUNCTION
77+
78+
func listSESTemplates(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
79+
// Create Session
80+
svc, err := SESClient(ctx, d)
81+
if err != nil {
82+
plugin.Logger(ctx).Error("aws_ses_template.listSESTemplates", "connection_error", err)
83+
return nil, err
84+
}
85+
if svc == nil {
86+
// Unsupported region check
87+
return nil, nil
88+
}
89+
90+
maxItems := int32(1000)
91+
// Limiting the results
92+
if d.QueryContext.Limit != nil {
93+
limit := int32(*d.QueryContext.Limit)
94+
if limit < maxItems {
95+
maxItems = limit
96+
}
97+
}
98+
99+
input := &ses.ListTemplatesInput{
100+
MaxItems: &maxItems,
101+
}
102+
103+
// List call
104+
output, err := svc.ListTemplates(ctx, input)
105+
if err != nil {
106+
plugin.Logger(ctx).Error("aws_ses_template.listSESTemplates", "api_error", err)
107+
return nil, err
108+
}
109+
110+
for _, template := range output.TemplatesMetadata {
111+
d.StreamListItem(ctx, template)
112+
113+
// Context can be cancelled due to manual cancellation or the limit has been hit
114+
if d.RowsRemaining(ctx) == 0 {
115+
return nil, nil
116+
}
117+
}
118+
119+
return nil, nil
120+
}
121+
122+
//// HYDRATE FUNCTIONS
123+
124+
func getSESTemplateDetails(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
125+
templateName := h.Item.(types.TemplateMetadata).Name
126+
127+
if templateName == nil {
128+
return nil, nil
129+
}
130+
if d.EqualsQualString("name") != "" && *templateName != d.EqualsQualString("name") {
131+
return nil, nil
132+
}
133+
134+
svc, err := SESClient(ctx, d)
135+
if err != nil {
136+
plugin.Logger(ctx).Error("aws_ses_template.getSESTemplateDetails", "connection_error", err)
137+
return nil, err
138+
}
139+
if svc == nil {
140+
return nil, nil
141+
}
142+
143+
params := &ses.GetTemplateInput{
144+
TemplateName: templateName,
145+
}
146+
147+
op, err := svc.GetTemplate(ctx, params)
148+
if err != nil {
149+
plugin.Logger(ctx).Error("aws_ses_template.getSESTemplateDetails", "api_error", err)
150+
return nil, err
151+
}
152+
153+
return op.Template, nil
154+
}

docs/tables/aws_ses_template.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
title: "Steampipe Table: aws_ses_template - Query AWS SES Templates using SQL"
3+
description: "Allows users to query AWS SES Templates and retrieve detailed information about each template, including its name, subject, content, and timestamps."
4+
folder: "SES"
5+
---
6+
7+
# Table: aws_ses_template - Query AWS SES Templates using SQL
8+
9+
The AWS SES Template is a feature of Amazon Simple Email Service (SES) that allows you to create and manage email templates. These templates can include both HTML and text content, along with variables that can be replaced with actual values when sending emails. Templates help maintain consistent branding and messaging across your email communications while simplifying the email sending process.
10+
11+
## Table Usage Guide
12+
13+
The `aws_ses_template` table in Steampipe provides you with information about email templates within AWS Simple Email Service (SES). This table allows you, as a DevOps engineer or email administrator, to query template-specific details, including the template name, subject line, HTML and text content, and creation timestamp. You can utilize this table to gather insights on your email templates, such as their content, creation dates, and usage patterns. The schema outlines the various attributes of the SES template for you, including the template name, subject part, text part, HTML part, and associated metadata.
14+
15+
## Examples
16+
17+
### Basic info
18+
Explore the basic information of your AWS SES templates, including their names, subjects, and creation timestamps. This can help you maintain an overview of your email templates and their metadata.
19+
20+
```sql+postgres
21+
select
22+
name,
23+
subject_part,
24+
created_timestamp
25+
from
26+
aws_ses_template;
27+
```
28+
29+
```sql+sqlite
30+
select
31+
name,
32+
subject_part,
33+
created_timestamp
34+
from
35+
aws_ses_template;
36+
```
37+
38+
### Get template details by name
39+
Retrieve detailed information about a specific template, including its subject line and content. This is useful for reviewing or updating specific templates.
40+
41+
```sql+postgres
42+
select
43+
name,
44+
subject_part,
45+
text_part,
46+
html_part,
47+
created_timestamp
48+
from
49+
aws_ses_template
50+
where
51+
name = 'MyTemplate';
52+
```
53+
54+
```sql+sqlite
55+
select
56+
name,
57+
subject_part,
58+
text_part,
59+
html_part,
60+
created_timestamp
61+
from
62+
aws_ses_template
63+
where
64+
name = 'MyTemplate';
65+
```
66+
67+
### List templates created in the last 30 days
68+
Identify recently created templates to track new additions to your email template library. This can help in maintaining an up-to-date inventory of your email templates.
69+
70+
```sql+postgres
71+
select
72+
name,
73+
subject_part,
74+
created_timestamp
75+
from
76+
aws_ses_template
77+
where
78+
created_timestamp >= now() - interval '30 days'
79+
order by
80+
created_timestamp desc;
81+
```
82+
83+
```sql+sqlite
84+
select
85+
name,
86+
subject_part,
87+
created_timestamp
88+
from
89+
aws_ses_template
90+
where
91+
created_timestamp >= datetime('now', '-30 days')
92+
order by
93+
created_timestamp desc;
94+
```
95+
96+
### List templates with HTML content
97+
Find templates that include HTML formatting, which is useful for identifying templates that require special rendering or may need additional testing across different email clients.
98+
99+
```sql+postgres
100+
select
101+
name,
102+
subject_part,
103+
html_part
104+
from
105+
aws_ses_template
106+
where
107+
html_part is not null;
108+
```
109+
110+
```sql+sqlite
111+
select
112+
name,
113+
subject_part,
114+
html_part
115+
from
116+
aws_ses_template
117+
where
118+
html_part is not null;
119+
```
120+
121+
### List templates with text-only content
122+
Identify templates that contain only plain text content, which can be useful for ensuring accessibility and compatibility with all email clients.
123+
124+
```sql+postgres
125+
select
126+
name,
127+
subject_part,
128+
text_part
129+
from
130+
aws_ses_template
131+
where
132+
html_part is null
133+
and text_part is not null;
134+
```
135+
136+
```sql+sqlite
137+
select
138+
name,
139+
subject_part,
140+
text_part
141+
from
142+
aws_ses_template
143+
where
144+
html_part is null
145+
and text_part is not null;
146+
```

0 commit comments

Comments
 (0)