0
votes

I'm new to Serverless framework. Is there a way to deploy the functions from NodeJS with Serverless framework in order to have the same code in my local src files than in Lambda functions? I would like to see the original code, and maybe put there manually some console.log, but all I see is minified code:

enter image description here

serverless.ymp code

service: XXX
provider:
name: aws
runtime: nodejs12.x
region: ${opt:region, 'us-east-2'}
stage: ${opt:stage, 'dev'}
tags:
    datadog: ${self:provider.stage}
environment:
    DYNAMODB_XXXXXS: ${self:provider.stage}-banks
    DYNAMODB_XXXXX_ACCOUNTS: ${self:provider.stage}-bank-accounts
    NODE_STAGE: ${self:provider.stage}
iamRoleStatements:
    - Effect: Allow
    Action:
        - logs:CreateLogGroup
        - logs:CreateLogStream
        - logs:PutLogEvents
    Resource: "arn:aws:logs:*:*:*"
    - Effect: Allow
    Action:
        - dynamodb:Query
    Resource:
        - "arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.DYNAMODB_XXXXXS}"
        - "arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.DYNAMODB_XXXXXS}/*"
    - Effect: Allow
    Action:
        - dynamodb:PutItem
    Resource:
        - "arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.DYNAMODB_XXXXX_ACCOUNTS}"
functions:
banks:
    handler: src/index.handler
    events:
    - http:
        path: /banks
        method: post
        cors: true
        authorizer:
            name: authorizer
            arn: arn:aws:cognito-idp:${self:provider.region}:2XXXX4:userpool/${self:custom.XXX.cognito.userpool}
    - http:
        path: /banks
        method: get
        cors: true
        authorizer:
            name: authorizer
            arn: arn:aws:cognito-idp:${self:provider.region}:XXXX04:userpool/${self:custom.XXx.cognito.userpool}
plugins:
- serverless-dynamodb-local
- serverless-webpack
- serverless-offline
package:
individually: true
exclude:
    - node_modules/**
resources:
Resources:
    DynamoDBTableBanks:
    Type: AWS::DynamoDB::Table
    Properties:
        TableName: ${self:provider.environment.DYNAMODB_XXXXXS}
        KeySchema:
        - AttributeName: code
            KeyType: HASH
        - AttributeName: agent
            KeyType: RANGE
        AttributeDefinitions:
        - AttributeName: code
            AttributeType: S
        - AttributeName: agent
            AttributeType: S
        - AttributeName: country
            AttributeType: S
        GlobalSecondaryIndexes:
        - IndexName: banksByAgentCountry
            KeySchema:
            - AttributeName: agent
                KeyType: HASH
            - AttributeName: country
                KeyType: RANGE
            Projection:
            ProjectionType: "ALL"
            ProvisionedThroughput:
            ReadCapacityUnits: 1
            WriteCapacityUnits: 1
        ProvisionedThroughput:
        ReadCapacityUnits: 1
        WriteCapacityUnits: 1
    DynamoDBTableBankAccount:
    Type: AWS::DynamoDB::Table
    Properties:
        TableName: ${self:provider.environment.DYNAMODB_XXXXX_ACCOUNTS}
        KeySchema:
        - AttributeName: id
            KeyType: HASH
        - AttributeName: receiverId
            KeyType: RANGE
        AttributeDefinitions:
        - AttributeName: id
            AttributeType: S
        - AttributeName: receiverId
            AttributeType: S
        ProvisionedThroughput:
        ReadCapacityUnits: 1
        WriteCapacityUnits: 1
custom:
XXXX:
    cognito:
    userpool: ${env:COGNITO_USER_POOL_ID, 'us-east-2_XXXX'}
dynamodb:
    stages:
    - dev
    start:
    convertEmptyValues: true
    heapInitial: 200m
    heapMax: 1g
    inMemory: true
    migrate: true
    port: 8000
webpack:
    webpackConfig: "webpack.config.js"
    packager: "npm"
    includeModules:
    forceExclude:
        - aws-sdk
1
Can you show your serverless.yml and the relevant function code? - jellycsc
@jellycsc done, the question now have the file - pmiranda

1 Answers

0
votes

It shouldn't be necessary. Just add your console.log to your code and you will see it echo out in CloudWatch when you test it in Lambda. If you would like to improve the feedback loop, consider using a tool like Studio developed by the team at Serverless designed to give you a dev mode experience. You just need to connect to the Serverless Framework Dashboard (https://www.serverless.com/framework/docs/dashboard#enabling-the-dashboard-on-existing-serverless-framework-services), then on CLI run serverless dev and now when you save your Lambda handler code it will automatically detect that, upload it into AWS in seconds and give you a postman style interface to test. Just click the "studio" on the top menu of the dashboard to access it.