Comments (16)
I've been playing around with this for a little while now, as well as diving into other projects that do something similar like serverless-offline which seems to use babel to get the output path it looks like. They set the 'location' at startup time. I think this could be done similarly when loading in the serverless config.
This would also enable the opportunity to put in the serverless directory in the config as well. Let me know your thoughts on this. The other way to do this is to use variables however that doesn't seem like as clean of a solution to me as handling would need to be added in lambdaSource.js
to cater for it.
from aws-utils.
Since serverless-offline appends the webpack location to the function handler (see: index.js) using Babel I believe, putting an environment variable in the handler would break functionality with serverless-offline and serverless-webpack.
from aws-utils.
@cbaron but good that you mentioned readme, from where it should be buildPrefix
, not modulePrefix
. My problem is solved )
from aws-utils.
@amalow -- Hello!
So glad that people are using the emulator! I'll bring up your use case with the team and look at invoking a lambda method implemented in TS, but I'm curious about a few things.
Its unclear what you mean by Typescript (therefore webpack)
-- could you give me some more information about how you're integrating TS with Webpack?
Why is manually prepending "./webpack/service"
not the best way to do it?
If we are running a lambda method in javascript on AWS, I would expect you to have some process which compiles Typescript to Javascript. I would expect that this javascript should be invoked by the emulator, as it will also be invoked by lambda. But perhaps I'm missing something?
from aws-utils.
Hi @cbaron
We use serverless-webpack to handle automatically transpiling our typescript code into Javascript, by default this plugin writes out to ./webpack/service
however that can be configured in the project's webpack config so prepending would not catch all cases if someone had customised their configuration. I'm thinking the best way to do this is to add an option in the project's serverless.yml
that indicates the executable code directory is different to the default?
Perhaps this is out of the scope of this plugin I'm not too sure.
from aws-utils.
Got it. Since we're using serverless in our emulator, you should be able to use you're own variables when defining the location of your lambda data source.
Let me know if that solves your use case!
from aws-utils.
I'm confused how variables will not give you a clean solution. Can you give me an explicit example of your ideal use case so that we can implement a solution?
from aws-utils.
I'm happy to put up a PR with an implementation. The variable method I'm suggesting would be something like:
custom: appsync-offline: port: 60004 modulePrefix: '.webpack/service'
In serverless.yml
and then in lambdaSource.js
const lambdaSource = async (
{
dynamodbEndpoint,
dynamodbTables,
serverlessConfig: { functions, custom },
serverlessDirectory,
},
fn,
{ payload },
) => {
const fnConfig = functions[fn];
const [handlerPath, handlerMethod] = fnConfig.handler.split('.');
let modulePrefix = '';
if (custom['appsync-offline'] && custom['appsync-offline']['modulePrefix']) {
modulePrefix = custom['appsync-offline']['modulePrefix'];
}
const fullPath = path.join(serverlessDirectory, modulePrefix, handlerPath);
// rest unchanged
}
Let me know what you think of this solution, I'm happy to put a PR up with it if it's acceptable.
from aws-utils.
Hmm, If I understand your use case correctly, it can be solved by utilizing environment variables in serverless.
Please let me know if I'm missing something.
from aws-utils.
Ahh, got it, your PR suggestion looks good to me.
from aws-utils.
Closing this as PR is merged in.
from aws-utils.
I may not correct undetstand how it suppose to work but with this config:
custom:
accountId: 565955521116
appsync-offline:
port: 60004
modulePrefix: 'dist/service/'
functions:
getReservations:
handler: handler.getReservations
getTransactions:
handler: handler.getTransactions
i'm getting error in emulator:
✖ error Query.getReservations failed
✖ error undefined
still, the only way how it does work for me is directly setting path to compiled code:
functions:
getReservations:
handler: dist/service/src/handler.getReservations
getTransactions:
handler: dist/service/src/handler.getTransactions
which is not good for me because I can't deploy serverless.yml in such state and I can't push it to git repo...
from aws-utils.
appsync-offline
only handles modulePrefix
-- it does not know what to do with port
Perhaps you need something like:
serverless-offline
port: 60004
@amalow -- care to chime in ?
from aws-utils.
I don't actually use appsync-offline
. Should I?
from aws-utils.
Its not necessary. After looking at your .yml file, I think you should try:
custom:
accountId: 565955521116
appsync-emulator:
modulePrefix: dist/service
functions:
getReservations:
handler: handler.getReservations
getTransactions:
handler: handler.getTransactions
Please look at the README! There is documentation surrounding this feature.
from aws-utils.
no, it does not work. The error is the same:
● start graphql
{
getReservations {
name
transactions(limit: 1) {
id
cost
}
}
}
● start Resolve: Query.getReservations [getReservations]
ℹ info Rendered Request:
{ version: '2017-02-28',
operation: 'Invoke',
payload: { field: 'getReservations', arguments: {}, source: {} } }
ℹ info Dispatch to source
{ name: 'getReservations', type: 'AWS_LAMBDA' }
✖ error Query.getReservations failed
✖ error undefined
I'm getting this error after running graphQl query from graphql playground
from aws-utils.
Related Issues (20)
- Cannot find function config for function : undefined HOT 1
- Failure trying to run tests HOT 3
- ValueMapper: JavaString HOT 2
- Feature request: Aurora (RDS) Serverless support HOT 1
- AppSync Emulator - Support Condition Expressions
- AppSync Emulator - Support $context.stash
- appsync emulator resultItems mapping template example does not work in AWS
- [appsync-emulator-serverless] Does not respect multiple appsSync API's in config HOT 2
- AppSync Emulator - Support RegEx in string split
- Cannot Install on Windows HOT 1
- [appsync-emulator-serverless] Conflicting peer dependencies
- Bug with getting PID by port HOT 9
- Lambda datasource docker HOT 12
- Emulator does not throw error when AppSync does
- AppSync Emulator - AWSEmail and AWSURL HOT 1
- Incorrect string equality in VTL templates HOT 1
- Unable to Invoke lambda function HOT 2
- Mismatch between AWSJSON and AppSync
- Assertions within createSchema method prevent DynamoDB from being null HOT 1
- Incorrect $util.isNullOrEmpty check in appsynce-emulator HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-utils.