Repository: serverless/serverless (JavaScript)
Date: 2019-06-26 13:01:09+00:00
Task type: Bug Fix

Issue:
Enabling websocket logs fails deployment
<!--
1. If you have a question and not a bug report please ask first at http://forum.serverless.com
2. Please check if an issue already exists. This bug may have already been documented
3. Check out and follow our Guidelines: https://github.com/serverless/serverless/blob/master/CONTRIBUTING.md
4. Fill out the whole template so we have a good overview on the issue
5. Do not remove any section of the template. If something is not applicable leave it empty but leave it in the Issue
6. Please follow the template, otherwise we'll have to ask you to update it
-->

# This is a Bug Report

## Description

* What went wrong?

Enabling websocket access logs cause deployment to fail.

* What did you expect should have happened?

Deployment should have succeeded.

* What was the config you used?

```yaml
  logs:
    websocket: true
```

* What stacktrace or error message from your provider did you see?

> An error occurred: WebsocketsDeploymentStage - Access log destination must only contain characters a-z, A-Z, 0-9, '_', '-', '/', '.': 'log-group:/aws/websocket/websocket-authorizer-example-dev:*' (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: 05d5c056-97e5-11e9-bd07-b9055926f0a6).

## Additional Data

It seems that the issue is on AWS side. The generated template looks correct, and I get the same error trying to manually configure websocket access logs through the console.

* ***Serverless Framework Version you're using***: 1.45.1
* ***Operating System***: linux
* ***Stack Trace***: n/a
* ***Provider Error messages***: see above

Enabling websocket logs fails deployment
<!--
1. If you have a question and not a bug report please ask first at http://forum.serverless.com
2. Please check if an issue already exists. This bug may have already been documented
3. Check out and follow our Guidelines: https://github.com/serverless/serverless/blob/master/CONTRIBUTING.md
4. Fill out the whole template so we have a good overview on the issue
5. Do not remove any section of the template. If something is not applicable leave it empty but leave it in the Issue
6. Please follow the template, otherwise we'll have to ask you to update it
-->

# This is a Bug Report

## Description

* What went wrong?

Enabling websocket access logs cause deployment to fail.

* What did you expect should have happened?

Deployment should have succeeded.

* What was the config you used?

```yaml
  logs:
    websocket: true
```

* What stacktrace or error message from your provider did you see?

> An error occurred: WebsocketsDeploymentStage - Access log destination must only contain characters a-z, A-Z, 0-9, '_', '-', '/', '.': 'log-group:/aws/websocket/websocket-authorizer-example-dev:*' (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: 05d5c056-97e5-11e9-bd07-b9055926f0a6).

## Additional Data

It seems that the issue is on AWS side. The generated template looks correct, and I get the same error trying to manually configure websocket access logs through the console.

* ***Serverless Framework Version you're using***: 1.45.1
* ***Operating System***: linux
* ***Stack Trace***: n/a
* ***Provider Error messages***: see above



Issue discussion:

Solution patch:
diff --git a/lib/plugins/aws/package/compile/events/websockets/lib/stage.js b/lib/plugins/aws/package/compile/events/websockets/lib/stage.js
index 71c3498e6f1..af5b81e1e55 100644
--- a/lib/plugins/aws/package/compile/events/websockets/lib/stage.js
+++ b/lib/plugins/aws/package/compile/events/websockets/lib/stage.js
@@ -34,7 +34,7 @@ module.exports = {
       Object.assign(stageResource.Properties, {
         AccessLogSettings: {
           DestinationArn: {
-            'Fn::GetAtt': [logGroupLogicalId, 'Arn'],
+            'Fn::Sub': `arn:aws:logs:\${AWS::Region}:\${AWS::AccountId}:log-group:\${${logGroupLogicalId}}`,
           },
           Format: [
             '$context.identity.sourceIp',


Test patch:
diff --git a/lib/plugins/aws/package/compile/events/websockets/lib/stage.test.js b/lib/plugins/aws/package/compile/events/websockets/lib/stage.test.js
index ab931abd3bc..5bc91404f4f 100644
--- a/lib/plugins/aws/package/compile/events/websockets/lib/stage.test.js
+++ b/lib/plugins/aws/package/compile/events/websockets/lib/stage.test.js
@@ -81,7 +81,8 @@ describe('#compileStage()', () => {
             Description: 'Serverless Websockets',
             AccessLogSettings: {
               DestinationArn: {
-                'Fn::GetAtt': [logGroupLogicalId, 'Arn'],
+                'Fn::Sub':
+                  'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${WebsocketsLogGroup}',
               },
               Format: [
                 '$context.identity.sourceIp',