Skip to content

Commit 8b22443

Browse files
authored
Merge pull request #220 from sebflipper/add-AWS-LogGroup
Added automatic CloudWatch LogGroup creation & deletion with expiry
2 parents c30beec + 53384bb commit 8b22443

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
language: node_js
22
node_js:
3-
- "6.10"
4-
- "8.10"
3+
- "8"
4+
- "10"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Tired of 🚀 **deploying**, ✏️ **updating**, and ❌ **deleting** your AppS
2626
<summary><strong>Table of Contents</strong> (click to expand)</summary>
2727

2828
* [Getting Started](#-getting-started)
29+
* [Minimum requirements](#-minimum-requirements)
2930
* [Installation](#-installation)
3031
* [Usage](#️-usage)
3132
* [Notes](#-notes)
@@ -43,6 +44,11 @@ Be sure to check out all that <a href="https://aws.amazon.com/appsync" target="_
4344
* <a target="_blank" href="https://docs.aws.amazon.com/appsync/latest/devguide/tutorials.html">Data Sources and Resolvers</a> - Get more information on what data sources are supported and how to set them up!
4445
* <a target="_blank" href="https://docs.aws.amazon.com/appsync/latest/devguide/security.html">Security</a> - Checkout this guide to find out more information on securing your API endpoints with AWS_IAM or Cognito User Pools!
4546

47+
## 🛠 Minimum requirements
48+
49+
* [Node.js v8 or higher](https://nodejs.org)
50+
* [Serverless v1.30.0 or higher](https://github.com/serverless/serverless)
51+
4652
## 💾 Installation
4753

4854
Install the plugin via <a href="https://yarnpkg.com/lang/en/docs/install/">Yarn</a> (recommended)

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ class ServerlessAppsyncPlugin {
303303
},
304304
},
305305
},
306+
...config.logConfig && config.logConfig.level && {
307+
[`${logicalIdGraphQLApi}LogGroup`]: {
308+
Type: 'AWS::Logs::LogGroup',
309+
Properties: {
310+
LogGroupName: { 'Fn::Join': ['/', ['/aws/appsync/apis', { 'Fn::GetAtt': [logicalIdGraphQLApi, 'ApiId'] }]] },
311+
RetentionInDays: this.serverless.service.provider.logRetentionInDays,
312+
},
313+
},
314+
},
306315
};
307316
}
308317

index.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,33 @@ describe("appsync config", () => {
104104
expect(role).toEqual({});
105105
});
106106

107+
test('appsync cloudwatch log group is not created when are not logs enabled', () => {
108+
const resources = plugin.getGraphQlApiEndpointResource(config);
109+
expect(resources.GraphQlApiLogGroup).toBeUndefined();
110+
});
111+
112+
test('appsync cloudwatch log group is created when logs enabled', () => {
113+
serverless.service.provider.logRetentionInDays = 14;
114+
const resources = plugin.getGraphQlApiEndpointResource({
115+
...config,
116+
logConfig: {
117+
level: 'ALL',
118+
},
119+
});
120+
121+
expect(resources.GraphQlApiLogGroup).toEqual({
122+
Properties: {
123+
LogGroupName: {
124+
'Fn::Join': ['/', ['/aws/appsync/apis', {
125+
'Fn::GetAtt': ['GraphQlApi', 'ApiId'],
126+
}]],
127+
},
128+
RetentionInDays: 14,
129+
},
130+
Type: 'AWS::Logs::LogGroup',
131+
});
132+
});
133+
107134
test("Datasource generates lambdaFunctionArn from functionName", () => {
108135

109136
Object.assign(

0 commit comments

Comments
 (0)