Skip to content

Add aws_ses_template table #2480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aws/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"aws_servicequotas_service_quota_change_request": tableAwsServiceQuotasServiceQuotaChangeRequest(ctx),
"aws_ses_domain_identity": tableAwsSESDomainIdentity(ctx),
"aws_ses_email_identity": tableAwsSESEmailIdentity(ctx),
"aws_ses_template": tableAwsSESTemplate(ctx),
"aws_sfn_state_machine": tableAwsStepFunctionsStateMachine(ctx),
"aws_sfn_state_machine_execution": tableAwsStepFunctionsStateMachineExecution(ctx),
"aws_sfn_state_machine_execution_history": tableAwsStepFunctionsStateMachineExecutionHistory(ctx),
Expand Down
154 changes: 154 additions & 0 deletions aws/table_aws_ses_template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package aws

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/ses"
"github.com/aws/aws-sdk-go-v2/service/ses/types"

"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)

func tableAwsSESTemplate(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_ses_template",
Description: "AWS SES Template",
List: &plugin.ListConfig{
Hydrate: listSESTemplates,
KeyColumns: []*plugin.KeyColumn{
{
Name: "name",
Require: plugin.Optional,
},
},
Tags: map[string]string{"service": "ses", "action": "ListTemplates"},
},
HydrateConfig: []plugin.HydrateConfig{
{
Func: getSESTemplateDetails,
Tags: map[string]string{"service": "ses", "action": "GetTemplate"},
},
},
GetMatrixItemFunc: SupportedRegionMatrix(AWS_EMAIL_SERVICE_ID),
Columns: awsRegionalColumns([]*plugin.Column{
{
Name: "name",
Description: "The name of the template.",
Type: proto.ColumnType_STRING,
},
{
Name: "subject_part",
Description: "The subject line of the email.",
Type: proto.ColumnType_STRING,
Hydrate: getSESTemplateDetails,
},
{
Name: "text_part",
Description: "The email body that will be visible to recipients whose email clients do not display HTML.",
Type: proto.ColumnType_STRING,
Hydrate: getSESTemplateDetails,
},
{
Name: "html_part",
Description: "The HTML body of the email.",
Type: proto.ColumnType_STRING,
Hydrate: getSESTemplateDetails,
},
{
Name: "created_timestamp",
Description: "The time and date the template was created.",
Type: proto.ColumnType_TIMESTAMP,
},

// Standard columns for all tables
{
Name: "title",
Description: resourceInterfaceDescription("title"),
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Name"),
},
}),
}
}

//// LIST FUNCTION

func listSESTemplates(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
// Create Session
svc, err := SESClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_ses_template.listSESTemplates", "connection_error", err)
return nil, err
}
if svc == nil {
// Unsupported region check
return nil, nil
}

maxItems := int32(1000)
// Limiting the results
if d.QueryContext.Limit != nil {
limit := int32(*d.QueryContext.Limit)
if limit < maxItems {
maxItems = limit
}
}

input := &ses.ListTemplatesInput{
MaxItems: &maxItems,
}

// List call
output, err := svc.ListTemplates(ctx, input)
if err != nil {
plugin.Logger(ctx).Error("aws_ses_template.listSESTemplates", "api_error", err)
return nil, err
}

for _, template := range output.TemplatesMetadata {
d.StreamListItem(ctx, template)

// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}

return nil, nil
}

//// HYDRATE FUNCTIONS

func getSESTemplateDetails(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
templateName := h.Item.(types.TemplateMetadata).Name

if templateName == nil {
return nil, nil
}
if d.EqualsQualString("name") != "" && *templateName != d.EqualsQualString("name") {
return nil, nil
}

svc, err := SESClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_ses_template.getSESTemplateDetails", "connection_error", err)
return nil, err
}
if svc == nil {
return nil, nil
}

params := &ses.GetTemplateInput{
TemplateName: templateName,
}

op, err := svc.GetTemplate(ctx, params)
if err != nil {
plugin.Logger(ctx).Error("aws_ses_template.getSESTemplateDetails", "api_error", err)
return nil, err
}

return op.Template, nil
}
146 changes: 146 additions & 0 deletions docs/tables/aws_ses_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
title: "Steampipe Table: aws_ses_template - Query AWS SES Templates using SQL"
description: "Allows users to query AWS SES Templates and retrieve detailed information about each template, including its name, subject, content, and timestamps."
folder: "SES"
---

# Table: aws_ses_template - Query AWS SES Templates using SQL

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.

## Table Usage Guide

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.

## Examples

### Basic info
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.

```sql+postgres
select
name,
subject_part,
created_timestamp
from
aws_ses_template;
```

```sql+sqlite
select
name,
subject_part,
created_timestamp
from
aws_ses_template;
```

### Get template details by name
Retrieve detailed information about a specific template, including its subject line and content. This is useful for reviewing or updating specific templates.

```sql+postgres
select
name,
subject_part,
text_part,
html_part,
created_timestamp
from
aws_ses_template
where
name = 'MyTemplate';
```

```sql+sqlite
select
name,
subject_part,
text_part,
html_part,
created_timestamp
from
aws_ses_template
where
name = 'MyTemplate';
```

### List templates created in the last 30 days
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.

```sql+postgres
select
name,
subject_part,
created_timestamp
from
aws_ses_template
where
created_timestamp >= now() - interval '30 days'
order by
created_timestamp desc;
```

```sql+sqlite
select
name,
subject_part,
created_timestamp
from
aws_ses_template
where
created_timestamp >= datetime('now', '-30 days')
order by
created_timestamp desc;
```

### List templates with HTML content
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.

```sql+postgres
select
name,
subject_part,
html_part
from
aws_ses_template
where
html_part is not null;
```

```sql+sqlite
select
name,
subject_part,
html_part
from
aws_ses_template
where
html_part is not null;
```

### List templates with text-only content
Identify templates that contain only plain text content, which can be useful for ensuring accessibility and compatibility with all email clients.

```sql+postgres
select
name,
subject_part,
text_part
from
aws_ses_template
where
html_part is null
and text_part is not null;
```

```sql+sqlite
select
name,
subject_part,
text_part
from
aws_ses_template
where
html_part is null
and text_part is not null;
```
Loading