Skip to content

Commit

Permalink
feat: Add vpc configuration (#416)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Cottone <daniel.cottone@asurion.com>
  • Loading branch information
casey-lemon and daniel-cottone authored May 27, 2020
1 parent 7cd156b commit 42994d3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ provider:
role: arn:aws:iam::123456789012:role/MyCustomRole
```

#### vpc

(Optional) VPC configuration for the log processor lambda to have.

```yaml
custom:
esLogs:
vpc:
securityGroupIds:
- sg-123456789
subnetIds:
- subnet-123456789
- subnet-223456789
- subnet-323456789
```

#### xrayTracingPermissions

(Optional) Adds AWS Xray writing permissions to the processor lambda. You will need these if you enable tracing for ApiGateway on your service.
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class ServerlessEsLogsPlugin {
}

private addLogProcesser(): void {
const { index, endpoint, tags } = this.custom().esLogs;
const { index, endpoint, tags, vpc } = this.custom().esLogs;
const tagsStringified = tags ? JSON.stringify(tags) : /* istanbul ignore next */ '';
const dirPath = path.join(this.serverless.config.servicePath, this.logProcesserDir);
const filePath = path.join(dirPath, 'index.js');
Expand All @@ -275,6 +275,7 @@ class ServerlessEsLogsPlugin {
ES_INDEX_PREFIX: index,
ES_TAGS: tagsStringified,
},
vpc,
events: [],
handler,
memorySize: 512,
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export interface IPluginOpts {
domainArn?: string;
index?: string;
vpc?: {
securityGroupIds: string[];
subnetIds: string[];
};
}

export interface IFormatterOpts {
Expand Down
23 changes: 23 additions & 0 deletions test/unit/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ describe('serverless-es-logs :: Plugin tests', () => {
expect(serverless.service.functions).to.have.property('esLogsProcesser');
expect(fs.existsSync(dirPath)).to.be.true;
});

it('should add vpc config if specified', () => {
const vpc = {
securityGroupIds: ['securityGroup'],
subnetIds: ['subnet']
};
const opts = {
service: {
custom: {
esLogs: {
endpoint: 'some_endpoint',
index: 'some_index',
vpc
},
},
},
};

serverless = new ServerlessBuilder(opts).build();
plugin = new ServerlessEsLogsPlugin(serverless, options);
plugin.hooks['after:package:initialize']();
expect(serverless.service.functions.esLogsProcesser).to.have.deep.property('vpc', vpc);
});
});
});

Expand Down

0 comments on commit 42994d3

Please sign in to comment.