Skip to content
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

feat(cost-explorer): AnomalyMonitor and AnomalySubscription type #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions cost-explorer/anomaly-monitor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Distribution / packaging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitignore can be removed

build/
dist/

# Unit test / coverage reports
.cache
.hypothesis/
.pytest_cache/

# RPDK logs
rpdk.log

# Node.js
node_modules/
coverage/

# contains credentials
sam-tests/
2 changes: 2 additions & 0 deletions cost-explorer/anomaly-monitor/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
optional = false
save = false
11 changes: 11 additions & 0 deletions cost-explorer/anomaly-monitor/.rpdk-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"typeName": "Community::CostExplorer::AnomalyMonitor",
"language": "typescript",
"runtime": "nodejs12.x",
"entrypoint": "dist/handlers.entrypoint",
"testEntrypoint": "dist/handlers.testEntrypoint",
"settings": {
"useDocker": false,
"protocolVersion": "2.0.0"
}
}
39 changes: 39 additions & 0 deletions cost-explorer/anomaly-monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Community::CostExplorer::AnomalyMonitor

Congratulations on starting development! Next steps:

1. Write the JSON schema describing your resource, [community-costexplorer-anomalymonitor.json](./community-costexplorer-anomalymonitor.json)
2. Implement your resource handlers in [handlers.ts](./community-costexplorer-anomalymonitor/handlers.ts)

> Don't modify [models.ts](./community-costexplorer-anomalymonitor/models.ts) by hand, any modifications will be overwritten when the `generate` or `package` commands are run.

Implement CloudFormation resource here. Each function must always return a ProgressEvent.

```typescript
const progress: ProgressEvent = ProgressEvent.builder()

// Required
// Must be one of OperationStatus.InProgress, OperationStatus.Failed, OperationStatus.Success
.status(OperationStatus.InProgress)
// Required on SUCCESS (except for LIST where resourceModels is required)
// The current resource model after the operation; instance of ResourceModel class
.resourceModel(model)
.resourceModels(null)
// Required on FAILED
// Customer-facing message, displayed in e.g. CloudFormation stack events
.message('')
// Required on FAILED a HandlerErrorCode
.errorCode(HandlerErrorCode.InternalFailure)
// Optional
// Use to store any state between re-invocation via IN_PROGRESS
.callbackContext({})
// Required on IN_PROGRESS
// The number of seconds to delay before re-invocation
.callbackDelaySeconds(0)

.build()
```

While importing the [cfn-rpdk](https://github.com/eduardomourar/cloudformation-cli-typescript-plugin) library, failures can be passed back to CloudFormation by either raising an exception from `exceptions`, or setting the ProgressEvent's `status` to `OperationStatus.Failed` and `errorCode` to one of `HandlerErrorCode`. There is a static helper function, `ProgressEvent.failed`, for this common case.

Keep in mind, during runtime all logs will be delivered to CloudWatch except those used with `debug` method.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"typeName": "Community::CostExplorer::AnomalyMonitor",
"description": "An example resource schema demonstrating some basic constructs and validation rules.",
"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-rpdk.git",
"definitions": {
},
"properties": {
"MonitorName": {
"type": "string"
},
"MonitorType": {
"type": "string",
"enum": [
"DIMENSIONAL",
"CUSTOM"
]
},
"MonitorDimension": {
"type": "string",
"enum": [
"SERVICE"
]
},
"MonitorSpecification": {
"type": "object"
},
"DimensionalValueCount": {
"type": "number"
},
"Arn": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"MonitorName",
"MonitorType",
"MonitorDimension"
],
"readOnlyProperties": [
"/properties/Arn"
],
"primaryIdentifier": [
"/properties/Arn"
],
"handlers": {
"create": {
"permissions": [
"costExplorer:createAnomalyMonitor"
]
},
"read": {
"permissions": [

]
},
"update": {
"permissions": [
"costExplorer:updateAnomalyMonitor"
]
},
"delete": {
"permissions": [
"costExplorer:deleteAnomalyMonitor"
]
},
"list": {
"permissions": [

]
}
}
}
97 changes: 97 additions & 0 deletions cost-explorer/anomaly-monitor/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Community::CostExplorer::AnomalyMonitor

An example resource schema demonstrating some basic constructs and validation rules.

## Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

### JSON

<pre>
{
"Type" : "Community::CostExplorer::AnomalyMonitor",
"Properties" : {
"<a href="#monitorname" title="MonitorName">MonitorName</a>" : <i>String</i>,
"<a href="#monitortype" title="MonitorType">MonitorType</a>" : <i>String</i>,
"<a href="#monitordimension" title="MonitorDimension">MonitorDimension</a>" : <i>String</i>,
"<a href="#monitorspecification" title="MonitorSpecification">MonitorSpecification</a>" : <i>Map</i>,
"<a href="#dimensionalvaluecount" title="DimensionalValueCount">DimensionalValueCount</a>" : <i>Double</i>,
}
}
</pre>

### YAML

<pre>
Type: Community::CostExplorer::AnomalyMonitor
Properties:
<a href="#monitorname" title="MonitorName">MonitorName</a>: <i>String</i>
<a href="#monitortype" title="MonitorType">MonitorType</a>: <i>String</i>
<a href="#monitordimension" title="MonitorDimension">MonitorDimension</a>: <i>String</i>
<a href="#monitorspecification" title="MonitorSpecification">MonitorSpecification</a>: <i>Map</i>
<a href="#dimensionalvaluecount" title="DimensionalValueCount">DimensionalValueCount</a>: <i>Double</i>
</pre>

## Properties

#### MonitorName

_Required_: Yes

_Type_: String

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### MonitorType

_Required_: Yes

_Type_: String

_Allowed Values_: <code>DIMENSIONAL</code> | <code>CUSTOM</code>

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### MonitorDimension

_Required_: Yes

_Type_: String

_Allowed Values_: <code>SERVICE</code>

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### MonitorSpecification

_Required_: No

_Type_: Map

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### DimensionalValueCount

_Required_: No

_Type_: Double

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

## Return Values

### Ref

When you pass the logical ID of this resource to the intrinsic `Ref` function, Ref returns the Arn.

### Fn::GetAtt

The `Fn::GetAtt` intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

For more information about using the `Fn::GetAtt` intrinsic function, see [Fn::GetAtt](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html).

#### Arn

Returns the <code>Arn</code> value.

8 changes: 8 additions & 0 deletions cost-explorer/anomaly-monitor/example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: Sample template

Resources:
AnomalyMonitor:
Type: Community::CostExplorer::AnomalyMonitor
Properties:
MonitorName: 'test-monitor'
Loading