arabold / aws-to-slack

Forward AWS CloudWatch Alarms and other notifications from Amazon SNS to Slack.
MIT License
293 stars 112 forks source link

Not showing Commit message in CWLogs or Slack #71

Open jtwp opened 5 years ago

jtwp commented 5 years ago

Using a CloudWatch Rule to send CodeCommit changes, I see the below on the Slack Message;

Commit Message Could not inspect repository. Check logs for stack trace.

And in the CloudWatch Logs for the Function the following:

Failed to inspect branch: { TimeoutError: Socket timed out without establishing a connection at Timeout.connectTimeout

Is this a permissions issue or something else?

homeyjd commented 5 years ago

Probably not, but haven't seen that one before. Timeout is hard-coded here: https://github.com/arabold/aws-to-slack/blob/master/src/parsers/codecommit/repository.js#L65 Maybe try raising the timeouts to 10s/5s and see if this fixes?

jtwp commented 5 years ago

I upped it, and got to about 50s/10s, but still the same. However, on line 67:

let commitId = _.get(event, "detail.commitId");

I see the following warning:

_is not defined; please fix or add /global__/

is that normal?

jtwp commented 5 years ago

Any other ideas on this one?

homeyjd commented 5 years ago

The please fix or add global isn't a problem.

Strictly speaking, ESLint wants to see that /* global */ comment in each file, but if your IDE is complaining about it then it's not parsing the .eslintrc file correctly. Underscore is registered as a global: https://github.com/arabold/aws-to-slack/blob/master/.eslintrc#L11 The global is defined here: https://github.com/arabold/aws-to-slack/blob/master/src/eventdef.js#L6

The next debugging steps here would be to confirm that your function can reach ANY endpoint. Does this Lambda produce correctly-formatted messages for other types? What other environment variables have you set? How did you build the project when you deployed it?

jtwp commented 5 years ago

All the other functionality seems to work fine, and messages from other sources come through with all the detail; CloudWatch Alarms, CodeBuild, Pipeline etc all look good. The CodeCommit message also looks good and is formatted correctly, just unable to display the commit message.

I initially deployed the function from the Launch Stack button, but then manually updated the Lambda function from the latest code. If it'd missed something I would assume the function wouldn't work at all or have other issues, but it only seems to be this one issue. All other Lambda variables are as per the default set up.

I'll keep looking... It's not a deal breaker as we can see the commit in the console, but just would be nice to have it there in the message.

If it helps, this is what I get from a test message in the Lambda execution results:

`Response: null

Request ID: "8e6fa422-48f0-42a0-9b5d-e0a55165d0ed"

Function Logs: START RequestId: 8e6fa422-48f0-42a0-9b5d-e0a55165d0ed Version: $LATEST 2019-08-22T09:07:52.041Z 8e6fa422-48f0-42a0-9b5d-e0a55165d0ed Incoming Message: { "version": "0", "id": "01234567-0123-0123-0123-012345678901", "detail-type": "CodeCommit Repository State Change", "source": "aws.codecommit", "account": "123456789012", "time": "2017-06-12T10:23:43Z", "region": "us-east-1", "resources": [ "arn:aws:codecommit:us-east-1:123456789012:myRepo" ], "detail": { "event": "referenceUpdated", "repositoryName": "myRepo", "repositoryId": "12345678-1234-5678-abcd-12345678abcd", "referenceType": "branch", "referenceName": "myBranch", "referenceFullName": "refs/heads/myBranch", "commitId": "26a8f2EXAMPLE", "oldCommitId": "3e5983EXAMPLE" } } 2019-08-22T09:07:53.323Z 8e6fa422-48f0-42a0-9b5d-e0a55165d0ed repository.js: Failed to inspect branch: { TimeoutError: Socket timed out without establishing a connection at Timeout.connectTimeout [as _onTimeout] (/var/runtime/node_modules/aws-sdk/lib/http/node.js:69:15) at ontimeout (timers.js:482:11) at tryOnTimeout (timers.js:317:5) at Timer.listOnTimeout (timers.js:277:5) message: 'Socket timed out without establishing a connection', code: 'TimeoutError', time: 2019-08-22T09:07:53.322Z, region: 'us-east-1', hostname: 'codecommit.us-east-1.amazonaws.com', retryable: true } 2019-08-22T09:07:53.421Z 8e6fa422-48f0-42a0-9b5d-e0a55165d0ed Sending Slack message from Parser[codecommit/repository]: { "attachments": [ { "author_name": "AWS CodeCommit", "fallback": "myRepo: New commit pushed to repository myRepo", "color": "#A8A8A8", "title": "New commit pushed to repository myRepo", "title_link": "https://console.aws.amazon.com/codecommit/home?region=us-east-1#/repository/myRepo", "fields": [ { "title": "Repository", "value": "myRepo", "short": true }, { "title": "Branch", "value": "myBranch", "short": true }, { "title": "Commit Message", "value": "Could not inspect repository. Check logs for stack trace." } ], "mrkdwn_in": [ "title", "text" ], "ts": 1497263023 } ] } 2019-08-22T09:07:53.822Z 8e6fa422-48f0-42a0-9b5d-e0a55165d0ed Message posted successfully. END RequestId: 8e6fa422-48f0-42a0-9b5d-e0a55165d0ed REPORT RequestId: 8e6fa422-48f0-42a0-9b5d-e0a55165d0ed Duration: 1881.31 ms Billed Duration: 1900 ms Memory Size: 128 MB Max Memory Used: 85 MB
XRAY TraceId: 1-5d5e5b67-5f4c457402c2a2e00d489820 SegmentId: 53f36de06cffaf96 `

jtwp commented 5 years ago

As another test I have cloned the repo from new, and made a new release package and uploaded that to Lambda, but still get the same issue.

Should the .eslintrc file exist in the tree in the Lambda code? As the package doesn't seem to contain it.

homeyjd commented 4 years ago

The .eslintrc file only needs to exist on your local box. However, it won't impact execution of the runtime. It's a debug-time asset only.

You're not running your Lambda function in a VPC, are you? VPC's have custom routing rules that can limit what services are available.