可以在AWS上部署无服务器功能,调用本地语言,但是在AWS上找不到

时间:2019-03-30 19:24:23

标签: aws-lambda serverless-framework

我有点困惑,非常感谢您的帮助。我是无服务器的新手,并且想尝试一下。我已遵循此tutorial来设置无服务器测试功能。

我还提到过将功能部署到AWS:

ola@pad:~/projects/serverless$ sls deploy --stage dev --aws-profile numpy-serverless-agent
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Injecting required Python packages to package...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service numpy-test.zip file to S3 (6.41 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.......
Serverless: Stack update finished...
Service Information
service: numpy-test
stage: dev
region: us-east-1
stack: numpy-test-dev
resources: 5
api keys:
  None
endpoints:
  None
functions:
  test: numpy-test-dev-test
layers:
  None
ola@pad:~/projects/serverless$ 

在本地调用非常有效:

ola@pad:~/projects/serverless$ sls invoke local --f test
Your numpy array:

[[ 0  1  2  3  4]
 [ 5  6  7  8  9]
 [10 11 12 13 14]]
null
ola@pad:~/projects/serverless$ 

但是,由于找不到该功能,因此在AWS上调用失败:

ola@pad:~/projects/serverless$ sls invoke --f test

  Serverless Error ---------------------------------------

  Function not found: arn:aws:lambda:us-east-1:XXXXXXXX:function:numpy-test-dev-test

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information -----------------------------
     OS:                     linux
     Node Version:           10.15.1
     Serverless Version:     1.37.1

最后这是我的serverless.yml文件

# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
#    docs.serverless.com
#
# Happy Coding!

service: numpy-test

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"

provider:
  name: aws
  runtime: python3.6
  stage: dev
  region: us-east-1


plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: true

# you can overwrite defaults here

# you can define service wide environment variables here
#  environment:
#    variable1: value1

# you can add packaging information here
package:
#  include:
#    - include-me.py
#    - include-me-dir/**
  exclude:
    - node_modules/**

functions:
  test:
    handler: handler.test

#    The following are a few example events you can configure
#    NOTE: Please make sure to change your handler code to work with those events
#    Check the event documentation for details
#    events:
#      - http:
#          path: users/create
#          method: get
#      - websocket: $connect
#      - s3: ${env:BUCKET}
#      - schedule: rate(10 minutes)
#      - sns: greeter-topic
#      - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
#      - alexaSkill: amzn1.ask.skill.xx-xx-xx-xx
#      - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
#      - iot:
#          sql: "SELECT * FROM 'some_topic'"
#      - cloudwatchEvent:
#          event:
#            source:
#              - "aws.ec2"
#            detail-type:
#              - "EC2 Instance State-change Notification"
#            detail:
#              state:
#                - pending
#      - cloudwatchLog: '/aws/lambda/hello'
#      - cognitoUserPool:
#          pool: MyUserPool
#          trigger: PreSignUp

#    Define function environment variables here
#    environment:
#      variable2: value2

# you can add CloudFormation resource templates here
#resources:
#  Resources:
#    NewResource:
#      Type: AWS::S3::Bucket
#      Properties:
#        BucketName: my-new-bucket
#  Outputs:
#     NewOutput:
#       Description: "Description for the output"
#       Value: "Some output value"

1 个答案:

答案 0 :(得分:1)

在部署服务时,您通过传递参数--aws-profile numpy-serverless-agent使用了非默认的AWS配置文件。这意味着它已部署到此配置文件指定的帐户。

当尝试使用lambda时,您没有传递此参数,因此使用了默认配置文件,该配置文件可能指定了另一个AWS账户。