Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update for serverless/function milestone and new v11 APIs #1467

Merged
merged 12 commits into from Feb 12, 2021

Conversation

@gr2m gr2m requested a review from a team as a code owner January 22, 2021 22:33
@request-info
Copy link

request-info bot commented Jan 22, 2021

Thanks for opening this, but we'd appreciate a little more information. Could you update it with more details?

@todo
Copy link

todo bot commented Jan 22, 2021

Add short deployment instructions for Vercel, Begin, Cloudflare Functions, GItHub Actions, Azure, Lambda. Reference the example apps for more details -->

probot/docs/deployment.md

Lines 125 to 129 in 1a170da

<!-- TODO: Add short deployment instructions for Vercel, Begin, Cloudflare Functions, GItHub Actions, Azure, Lambda. Reference the example apps for more details -->
## Share the app
The Probot website includes a list of [featured apps](https://probot.github.io/apps). Consider [adding your app to the website](https://github.com/probot/probot.github.io/blob/master/CONTRIBUTING.md#adding-your-app) so others can discover and use it.


This comment was generated by todo based on a TODO comment in 1a170da in #1467. cc @probot.

@oscard0m
Copy link
Contributor

If you need help for the AWS let me know. Maybe I can help with that :)

@gr2m
Copy link
Contributor Author

gr2m commented Jan 23, 2021

Thanks @oscard0m! I'm still confused about what the simplest way is to deploy a function with dependencies to Lambda 🤷🏼 I guess everyone is using serverless to do it? Anything else?

@oscard0m
Copy link
Contributor

Thanks @oscard0m! I'm still confused about what the simplest way is to deploy a function with dependencies to Lambda 🤷🏼 I guess everyone is using serverless to do it? Anything else?

My experience is with serverless, yep.

@gr2m
Copy link
Contributor Author

gr2m commented Jan 23, 2021

I've installed serverless and trying to follow these instructions:
https://www.serverless.com/framework/docs/providers/aws/guide/quick-start/

In the "Test your service" section it says

Replace the URL in the following curl command with your returned endpoint URL, which you can find in the sls deploy output

But there is no URL in my output:

$ sls deploy -v
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service example-aws-lambda-serverless.zip file to S3 (121.82 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - example-aws-lambda-serverless-dev
CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - HelloLambdaFunction
CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - HelloLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - HelloLambdaVersionGu91BGSA6xKexM1kHFHhU2fYrigENcoexIRycHp7BM0
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - HelloLambdaVersionGu91BGSA6xKexM1kHFHhU2fYrigENcoexIRycHp7BM0
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Version - HelloLambdaVersionGu91BGSA6xKexM1kHFHhU2fYrigENcoexIRycHp7BM0
CloudFormation - UPDATE_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - example-aws-lambda-serverless-dev
CloudFormation - DELETE_SKIPPED - AWS::Lambda::Version - HelloLambdaVersionR9fQJlmpsWuJGQsMTI2FoefGyeQdf0X9lXqhWQP25lU
CloudFormation - UPDATE_COMPLETE - AWS::CloudFormation::Stack - example-aws-lambda-serverless-dev
Serverless: Stack update finished...
Service Information
service: example-aws-lambda-serverless
stage: dev
region: us-east-1
stack: example-aws-lambda-serverless-dev
resources: 8
api keys:
  None
endpoints:
  None
functions:
  hello: example-aws-lambda-serverless-dev-hello
layers:
  None

Stack Outputs
EnterpriseLogAccessIamRole: arn:aws:iam::152606098741:role/example-aws-lambda-server-EnterpriseLogAccessIamRo-11UMZPHFUH5EI
HelloLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-1:152606098741:function:example-aws-lambda-serverless-dev-hello:4
ServerlessDeploymentBucketName: example-aws-lambda-serve-serverlessdeploymentbuck-zv47sxrh0orp

Serverless: Publishing service to the Serverless Dashboard...
Serverless: Successfully published your service to the Serverless Dashboard: https://app.serverless.com/probot/apps/probot-hello-world-example/example-aws-lambda-serverless/dev/us-east-1

How do I find out the URL of my deployed app?

serverless
Getting started with the Serverless Framework on AWS Lambda

@gr2m
Copy link
Contributor Author

gr2m commented Jan 23, 2021

Ah I got it, nevermind my comment above, I had to add events.httpApi settings to my function in serverless.yml

functions:
  hello:
    handler: handler.hello
    events:
      - httpApi:
          path: /dev/hello
          method: post

@gr2m
Copy link
Contributor Author

gr2m commented Jan 24, 2021

@oscard0m I've created a repository and have a work-in-progress pull request for the initial implementation:
probot/example-aws-lambda-serverless#1

I've created the app (https://github.com/apps/probot-aws-lambda-example) and installed it on https://github.com/gr2m/sandbox. No errors are thrown, but no comment is posted either. I think the Probot function defined in ./app.js does not get loaded, but I don't know why. I don't know how to further debug the app right now. Could you give it a try? I can send you the credentials for the existing GitHub App, or setup a new app for testing

GitHub
GitHub is where people build software. More than 56 million people use GitHub to discover, fork, and contribute to over 100 million projects.
GitHub
description set by settings app? Contribute to gr2m/sandbox development by creating an account on GitHub.

@oscard0m
Copy link
Contributor

oscard0m commented Jan 24, 2021

@gr2m

I suspect the only step missing is to replace your Webhook URL in your Github App with the one of the Lambda Function. Could it be?

image


Trying to reproduce all the ecosystem examples you created:

  1. ✅ Forked Sandbox repo: https://github.com/oscard0m/sandbox/issues/9
  2. ✅ Created a Github App with Probot so I have access to configure it: https://github.com/apps/example-aws-lambda-serverless
  3. ✅ Installed example-aws-lambda-serverless in sanbox forked repo
  4. ✅ Deployed my AWS lambda function with Serverless successfully
  5. ✅ Configured Webhook in Github App to call to AWS Lambda Function:
    image
  6. ✅ Created a random issue in Sandbox forked repo https://github.com/oscard0m/sandbox/issues/9
  7. ✅ Serverless gets activity
    image
  8. ❌ The Github App is not able to comment the issue
  9. ⚠️ Checking CloudWatch in AWS you can see logs of the execution of your Lambda Function (probably I have something wrong on my end):
    image
    In my case there seem to be some credentials issues when trying to use Octokit:
    image

  • Make sure your Github App is calling you AWS Lambda Function via its Webhook (step 5)
  • Try to check in AWS CloudWatch the logs. (I think there is no option to connect logs to Serverless Dashboard with free plan) (step 9)

@gr2m
Copy link
Contributor Author

gr2m commented Jan 24, 2021

I suspect the only step missing is to replace your Webhook URL in your Github App with the one of the Lambda Function. Could it be?

no I set that URL correctly. I see the correct response to GitHub's webhook requests in the app registration's "Avanced" tab on GitHub

image

9\. Checking CloudWatch in AWS you can see logs of the execution of your Lambda Function (probably I have something wrong on my end):

sounds like the Webhook Secret is not configured correctly. I configured three parameters in the Serverless dashboard, that I reference in serverless.yml

image

Did you set these up?

@oscard0m
Copy link
Contributor

I was missing that part of the parameters. Now is running but no logs as it is happening to you. Checking Cloudwatch the Lambda is executed but no logs. Keep looking into it

@oscard0m
Copy link
Contributor

Did not have time to find the root of the issue. I have to go to 🛌🏽.

enabled DEBUG=webhooks:receiver and no activity apparently.

Adding some loggers on the way seems like the verification step is completed successfully but the receiver is not triggered. I will try to get some more time debugging it. Any idea on what it could be happening? Maybe a Promise not awaited makes the lambda die before?

(In my company we are using a super old version of @probot/serverless-lambda so I can't compare what we have there). We are using @probot/serverless-lambda@0.5.0 just in case you can find there some inspiration.

@gr2m

@gr2m
Copy link
Contributor Author

gr2m commented Jan 26, 2021

I see that the app was loaded in the logs

image

but no webhook seems to be handled

@helaili
Copy link
Contributor

helaili commented Jan 26, 2021

I have an app working here. I think you were just missing the parsing of the body.

@gr2m
Copy link
Contributor Author

gr2m commented Jan 27, 2021

Thanks @helaili, that made no difference. If you have the raw string available I would recommend to pass that to webhooks.verifyAndReceive(), the method will do the parsing before, but it will use the original string for the signature verification, instead of doing a JSON.stringify()

I also set NODE_ENV to production. I don't see any other differences ...

@gr2m
Copy link
Contributor Author

gr2m commented Jan 27, 2021

Oh wait, it did work, I just don't understand why lol
gr2m/sandbox#173 (comment)

@gr2m
Copy link
Contributor Author

gr2m commented Jan 27, 2021

I think you are right, I have to pass payload as object to verifyAndReceive, I miss remembered. I do think we should accept a string though, that's what we do in the verify method

@oscard0m
Copy link
Contributor

I think you are right, I have to pass payload as object to verifyAndReceive, I miss remembered. I do think we should accept a string though, that's what we do in the verify method

Do you want me to create a bug for this @gr2m ? (in @octokit)

@oscard0m
Copy link
Contributor

oscard0m commented Jan 28, 2021

I have an app working here. I think you were just missing the parsing of the body.

Thanks @helaili 🙌🏾

@gr2m
Copy link
Contributor Author

gr2m commented Jan 30, 2021

Do you want me to create a bug for this @gr2m ? (in @octokit)

Yes please @oscard0m thanks!

@oscard0m
Copy link
Contributor

oscard0m commented Feb 1, 2021

Do you want me to create a bug for this @gr2m ? (in @octokit)

Yes please @oscard0m thanks!

octokit/webhooks.js#420

@gr2m
Copy link
Contributor Author

gr2m commented Feb 1, 2021

Did anyone of you successfully deploy a serverless app via GitHub Actions using a serverless access key? I tried using https://github.com/marketplace/actions/serverless but I'm getting

Serverless Error ---------------------------------------
 
AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://slss.io/aws-creds-setup>.

Although the SERVERLESS_ACCESS_TOKEN environment variable is set

I was able to run it locally successfully

sls logout
SERVERLESS_ACCESS_TOKEN=... sls deploy

I also tried to checkout the PR into a new a fresh directory so that the .serverless folder does not exist. And it also just worked 😡 No idea why it just refuses to work on GitHub Actions

@gr2m
Copy link
Contributor Author

gr2m commented Feb 2, 2021

okay I think I understand why it's working locally. I had the ~/.aws/credentials file and once I renamed it I started seeing the same error locally

@gr2m
Copy link
Contributor Author

gr2m commented Feb 2, 2021

after removing the ~/.aws/credentials file I was able to run

SERVERLESS_ACCESS_KEY=... AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... sls deploy

But running the same on Actions gives me

   Serverless Error ---------------------------------------
 
  The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              12.20.1
     Framework Version:         2.21.1
     Plugin Version:            4.4.2
     SDK Version:               2.3.2
     Components Version:        3.6.0

Gosh I've spent the whole day on this :(

@oscard0m
Copy link
Contributor

oscard0m commented Feb 2, 2021

We don't use Github Actions for serverless deployment in my company so no experience with it.
Could be something related on how serverless reads or how Github Secrets parses the Private Key? (escaping / unscaping newlines for example)

@gr2m
Copy link
Contributor Author

gr2m commented Feb 2, 2021

Hallelujah the problem went away when I went back to use the serverless/github-action action

@oscard0m
Copy link
Contributor

oscard0m commented Feb 2, 2021

Hallelujah the problem went away when I went back to use the serverless/github-action action

What changed from first try?


Congrats 🎉🎊🎈🍾

@gr2m
Copy link
Contributor Author

gr2m commented Feb 2, 2021

What changed from first try?

The docs of the action suggest that you either set SERVERLESS_ACCESS_KEY or AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, but I had to set all three to make it work. I don't know why.

@@ -10,7 +10,7 @@ Every app can either be deployed stand-alone, or combined with other apps in one

**Contents:**

1. [Create the GitHub App](#create-the-github-app)
1. [Register the GitHub App](#register-the-github-app)
1. [Deploy the app](#deploy-the-app)
1. [Glitch](#glitch)
1. [Heroku](#heroku)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a link to Serverless here, too.

@gr2m
Copy link
Contributor Author

gr2m commented Feb 3, 2021

The race is on lol: probot/sandbox#8

image

@oscard0m
Copy link
Contributor

oscard0m commented Feb 3, 2021

Same code for three of them?

Also, lambas in same state (hot or asleep) @gr2m

@gr2m
Copy link
Contributor Author

gr2m commented Feb 3, 2021

Same code for three of them?

Yes, all use the same Probot app function

/**
 * @param {import('probot').Probot} app
 */
module.exports = (app) => {
  app.log("Yay! The app was loaded!");

  app.on("issues.opened", async (context) => {
    return context.octokit.issues.createComment(
      context.issue({ body: "Hello, World!" })
    );
  });
};

Also, lambas in same state (hot or asleep) @gr2m

It's not a scientific test 🤷🏼 just a fun observation. I guess we could create a new issue on a schedule and then another issue a few seconds later and then compare the times over time, but it's not a competition. There are other projects that probably do better at comparing the different providers

@gr2m
Copy link
Contributor Author

gr2m commented Feb 10, 2021

We now have 6 example apps for

  • AWS Lambda
  • Azure Functions
  • Google Cloud Platform
  • GitHub Action
  • Begin
  • Vercel

and adapters for

  • AWS Lambda
  • GitHub Actions
  • Azure Functions

(the other 3 work with Probot's built-in createNodeMiddleware export)

probot/sandbox#12

I'll update the docs, then we should be good for a more public launch to get Probot's serverless/function capabilities some traction

ZauberNerd and others added 6 commits February 12, 2021 12:39
The new types introduced in `@octokit/webhooks@7.22.0`, are incompatible with the current codebase. This will prevent users from getting anything newer than the pinned version in order to avoid type errors for end-users
@gr2m gr2m changed the title 🚧 docs: update for serverless/function milestone and new v11 APIs docs: update for serverless/function milestone and new v11 APIs Feb 12, 2021
@gr2m
Copy link
Contributor Author

gr2m commented Feb 12, 2021

Docs are not as great as they could be, but it's a start.

Contributions are very, very welcome!

@gr2m gr2m merged commit c612fc9 into master Feb 12, 2021
@gr2m gr2m deleted the docs-update branch February 12, 2021 21:08
@github-actions
Copy link

github-actions bot commented Mar 1, 2021

🎉 This PR is included in version 11.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants