Code Monkey home page Code Monkey logo

serverless-plugin-local-env's People

Contributors

build-user-mutualofenumclaw avatar dependabot[bot] avatar ebarbuti avatar nkeating-mutualofenumclaw avatar

Watchers

 avatar  avatar

serverless-plugin-local-env's Issues

Not working when resources are in a separate serverless.yml file?

Hi,

I tried to implement your solution but it does not seem to work in my case.

I created a S3 bucket in a separate yml file then I reference it from my main function serverless.yml:

S3 serverless.yml:

service: journey-automation-s3-storage-test
provider:
  name: aws
  stage: dev
  runtime: nodejs12.x
  region: eu-central-1
  profile: journeyautomation
resources:
  Resources:
    S3TestBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${opt:stage, self:provider.stage}-s3test-bucket
        AccessControl: PublicReadWrite
        PublicAccessBlockConfiguration:
          BlockPublicAcls: false
          BlockPublicPolicy: false
          IgnorePublicAcls: false
          RestrictPublicBuckets: false
        LifecycleConfiguration:
          Rules:
            - Status: Enabled
              Id: Delete 30 days old items
              ExpirationInDays: 30
    S3TestBucketPolicy:
      Type: AWS::S3::BucketPolicy
      DependsOn: S3TestBucket
      Properties:
        Bucket:
          Ref: S3TestBucket
        PolicyDocument:
          Version: '2012-10-17'
          Statement:
            - Sid: PublicAllAccess
              Effect: Allow
              Principal: '*'
              Action: 's3:*'
              Resource:
                Fn::Join:
                  - ''
                  - - Fn::GetAtt: [S3TestBucket, Arn]
                    - '/*'
  Outputs:
    S3TestBucketArn:
      Value:
        Fn::GetAtt:
          - S3TestBucket
          - Arn
      Export:
        Name: ${opt:stage, self:provider.stage}-S3TestBucketArn
    S3TestBucket:
      Value:
        Ref: S3TestBucket
      Export:
        Name: ${opt:stage, self:provider.stage}-S3TestBucket

Serverless.yml from my main function:

service: s3test
custom:
  serverless-offline:
    httpPort: 4000
provider:
  name: aws
  runtime: nodejs12.x
  profile: journeyautomation
  stage: dev
  region: eu-central-1
  tracing:
    apiGateway: true
    lambda: true
  logRetentionInDays: 30
  environment:
    S3_TEST_BUCKET:
      Fn::ImportValue: ${opt:stage, self:provider.stage}-S3TestBucket
functions:
  getFile:
    handler: handler.getFile
    events:
      - http:
          path: s3test/files
          method: get
          cors: ${self:custom.cors-config}
package:
  exclude:
    - .dynamodb/**
    - .nyc_output/**
    - coverage/**
    - test/**
    - .git/**
    - serverless.yml
    - .serverless/**
    - requests.http
    - files/**
    - node_modules/puppeteer/.local-chromium/**
plugins:
  - serverless-offline
  - '@moe-tech/serverless-plugin-local-env'

handler.js (stripped, just showing the piece of code that matters)

'use strict';

//#region Requires

const AWS = require('aws-sdk');
const logger = require('./lib/logger');

//#endregion

//#region AWS Resources

logger.info('process.env.S3_TEST_BUCKET: ' + process.env.S3_TEST_BUCKET);

//#endregion

Output shows:

offline: Starting Offline: dev/eu-central-1.
offline: Offline [http for lambda] listening on http://localhost:3002

   ┌────────────────────────────────────────────────────────────────────────────┐
   │                                                                            │
   │   GET  | http://localhost:4000/s3test/files                                │
   │   POST | http://localhost:4000/2015-03-31/functions/getFile/invocations    │
   │                                                                            │
   └────────────────────────────────────────────────────────────────────────────┘

offline: [HTTP] server ready: http://localhost:4000 �

offline: GET /s3test/files (λ: getFile)
2020-07-25 15:44:24: INFO: process.env.S3_TEST_BUCKET: [object Object]

As you can see, S3_TEST_BUCKET still shows as [object Object].

Am I using this properly?

Thanks.

Plugin activation

Hi Nikody,

I just faced this exact problem and saw your post referencing this plugin, which is exactly what I'm looking for, as I don't mind deploying the full stack to use its resources.

The thing is I'm running 1.63.0 (and previously tried with 1.59.)3, but haven't managed to make the plugin work at all, apart from the environment vars behaving as usual, what gave it away was the fact that it's not generating the invoke.cache.json under .serverless.

Also tried packaging and deploying the sample, packaging doesn't generate the cache, deploying fails as I don't have access to the secret manager resource needed :S

Let me know if the sample still works for you, or if there is anything I'm missing at all.

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.