mutual-of-enumclaw / serverless-plugin-local-env Goto Github PK
View Code? Open in Web Editor NEWThis plugin is used to resolve AWS resources in the debugger environment variables when using the serverless framework.
License: MIT License
This plugin is used to resolve AWS resources in the debugger environment variables when using the serverless framework.
License: MIT License
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.