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

APIGW not being deployed for endpoints #15

Open
revmischa opened this issue Oct 8, 2020 · 7 comments
Open

APIGW not being deployed for endpoints #15

revmischa opened this issue Oct 8, 2020 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@revmischa
Copy link
Contributor

Normal AWS provider outputs APIGW base URL and endpoint URLs. It's very helpful to have after doing a new deployment. Would be nice to have.

@revmischa revmischa changed the title sls info doesn't list endpoints sls info doesn't list endpoints Oct 8, 2020
@revmischa
Copy link
Contributor Author

Actually I guess it doesn't make any APIGW resources at all...

service: foo

provider:
  # CDK
  name: aws-cdk
  cdkModulePath: ./build/cdk
  stackName: "${self:service}-${self:provider.stage}"

  # node
  runtime: nodejs12.x

  # AWS
  stage: ${opt:stage, 'dev'}
  region: ${opt:region, 'us-east-1'}

  httpApi:
    cors: true
    payload: "2.0"
  logs:
    httpApi: true
  tracing:
    apiGateway: true
    lambda: true

package:
  exclude:
    - "node_modules/**"
    - "src/**"
    - "cdk/**"

plugins:
  - serverless-aws-cdk
  - serverless-offline
  - serverless-plugin-typescript
  - serverless-pseudo-parameters
  - serverless-dotenv-plugin

functions:
  testJson:
    handler: src/api/testTwilio.testJson
    events:
      - httpApi:
          method: POST
          path: /sms/testJson

No APIGateway resources are deployed

@revmischa revmischa changed the title sls info doesn't list endpoints APIGW not being deployed for endpoints Oct 8, 2020
@RichardDRJ
Copy link
Contributor

RichardDRJ commented Oct 9, 2020

Hey @revmischa, thanks for raising this. One of the aims of this project is to reduce extra magic in the serverless.yml, so it doesn't include e.g. the events key that you might be used to from the AWS provider. Instead, the idea is that you can define it yourself just as easily with all the benefits of using CDK directly.

On your other point around printing outputs, since the plugin doesn't have knowledge of these things, it can't print outputs; instead, it's recommended that you use stack outputs which are printed out by CDK by default.

I've created a PR (#16) to update the README to address both of these and make it explicit, as well as to provide extra examples for those use cases

@revmischa
Copy link
Contributor Author

Oh, that's disappointing. I still have to define the events because I want to test my endpoints with serverless-offline, and use httpApi authorizers and whatnot.

@RichardDRJ
Copy link
Contributor

Ah, that makes sense - I don't think I'll get a chance to dedicate much time to implementing that myself any time soon, but if it's required for interop with other plugins I'm more than happy to take a look at any PRs for it

@RichardDRJ RichardDRJ added enhancement New feature or request good first issue Good for newcomers labels Oct 9, 2020
@revmischa
Copy link
Contributor Author

I'm looking at trying to do this manually for now, I assume it'd go something like this:

import { api } from "serverless-aws-cdk"
import * as cdk from "@aws-cdk/core"
import { HttpApi, LambdaProxyIntegration, HttpMethod,PayloadFormatVersion } from "@aws-cdk/aws-apigatewayv2"

export class Api extends api.InfrastructureConstruct {
  constructor(scope: cdk.Construct, id: string, props: api.InfrastructureProps) {
    super(scope, id, props)

    // there will probably be a nicer L2 way of doing this

    const api = new HttpApi(this, "API", {
      corsPreflight: { allowCredentials: true, allowOrigins: ["*"] },
      createDefaultStage: true,
    })

    api.addRoutes({
      path: "/test",
      methods: [HttpMethod.GET],
      integration: new LambdaProxyIntegration({
        payloadFormatVersion: PayloadFormatVersion.VERSION_2_0,
        handler: ????? // what goes here?
      })
    })
  }
}

I'd need to connect my existing sls function by passing something that conforms to an IFunction

@RichardDRJ
Copy link
Contributor

props.functions is a mapping from functions as keyed in your serverless.yml to Function objects - you should be able to find the objext you need in there. From the serverless.yml you posted above, it should be props.functions["testJson"]

@revmischa
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants