Skip to content

Commit

Permalink
Merge pull request #220 from sebflipper/add-AWS-LogGroup
Browse files Browse the repository at this point in the history
Added automatic CloudWatch LogGroup creation & deletion with expiry
  • Loading branch information
sid88in authored Mar 3, 2019
2 parents c30beec + 53384bb commit 8b22443
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- "6.10"
- "8.10"
- "8"
- "10"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Tired of 🚀 **deploying**, ✏️ **updating**, and ❌ **deleting** your AppS
<summary><strong>Table of Contents</strong> (click to expand)</summary>

* [Getting Started](#-getting-started)
* [Minimum requirements](#-minimum-requirements)
* [Installation](#-installation)
* [Usage](#️-usage)
* [Notes](#-notes)
Expand All @@ -43,6 +44,11 @@ Be sure to check out all that <a href="https://aws.amazon.com/appsync" target="_
* <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!
* <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!

## 🛠 Minimum requirements

* [Node.js v8 or higher](https://nodejs.org)
* [Serverless v1.30.0 or higher](https://github.com/serverless/serverless)

## 💾 Installation

Install the plugin via <a href="https://yarnpkg.com/lang/en/docs/install/">Yarn</a> (recommended)
Expand Down
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ class ServerlessAppsyncPlugin {
},
},
},
...config.logConfig && config.logConfig.level && {
[`${logicalIdGraphQLApi}LogGroup`]: {
Type: 'AWS::Logs::LogGroup',
Properties: {
LogGroupName: { 'Fn::Join': ['/', ['/aws/appsync/apis', { 'Fn::GetAtt': [logicalIdGraphQLApi, 'ApiId'] }]] },
RetentionInDays: this.serverless.service.provider.logRetentionInDays,
},
},
},
};
}

Expand Down
27 changes: 27 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ describe("appsync config", () => {
expect(role).toEqual({});
});

test('appsync cloudwatch log group is not created when are not logs enabled', () => {
const resources = plugin.getGraphQlApiEndpointResource(config);
expect(resources.GraphQlApiLogGroup).toBeUndefined();
});

test('appsync cloudwatch log group is created when logs enabled', () => {
serverless.service.provider.logRetentionInDays = 14;
const resources = plugin.getGraphQlApiEndpointResource({
...config,
logConfig: {
level: 'ALL',
},
});

expect(resources.GraphQlApiLogGroup).toEqual({
Properties: {
LogGroupName: {
'Fn::Join': ['/', ['/aws/appsync/apis', {
'Fn::GetAtt': ['GraphQlApi', 'ApiId'],
}]],
},
RetentionInDays: 14,
},
Type: 'AWS::Logs::LogGroup',
});
});

test("Datasource generates lambdaFunctionArn from functionName", () => {

Object.assign(
Expand Down

0 comments on commit 8b22443

Please sign in to comment.