Amplify-cli: Restful API using existing Lambda function

Created on 28 Feb 2019  路  3Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
amplify 1.1.6 does not allow restful api to use existing Lambda

To Reproduce
Steps to reproduce the behavior:

  1. amplify api add -> REST
  2. Enter a label
  3. Enter a path
  4. It has only one option "Create a new Lambda function"

Expected behavior
Prior to upgrade, I was using 0.1.38 and amplify was able to pull all Lambda functions from the account in the region that I can use in the Amplify project

Desktop (please complete the following information):

  • OS: [e.g. iOS] OSX
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22] 1.1.6

Additional context
Add any other context about the problem here.

question

Most helpful comment

How can we reuse lambda functions across projects?

All 3 comments

This was intentionally removed to reduce the confusion it would cause when using with multienv.

If we allow choosing a lambda function, the same resource would be used for all the environment and break the resource isolation between environments.

We do support choosing a lambda function that is provisioned using CLI as we create a separate function for each environment.
Please feel free to re-open if this doesn't answer your question.

@kangks if you really want to use the lambda function in the aws account, just use the aws-sdk/client/lambda.

import Amplify, { Auth } from 'aws-amplify';

...
...
...

      Auth.currentCredentials()
      .then(credentials => {
        const lambda = new Lambda({
          region: "us-east-1",
          credentials: Auth.essentialCredentials(credentials)
        });

        var pullParams = {
          FunctionName : 'api-lambda-get',
          InvocationType : 'RequestResponse',
          LogType : 'None'
        };

        lambda.invoke(pullParams, function(err, data) {
          if (err) {
            console.err(err);
          } else {
            console.log(JSON.parse(data.Payload));
          }
        });
      });

How can we reuse lambda functions across projects?

Was this page helpful?
0 / 5 - 0 ratings