部署期间无服务器异步功能错误

时间:2018-07-30 22:21:16

标签: webpack aws-serverless

使用节点6.10 AWS Lambda运行时设置新的无服务器环境1.29.0。

在部署项目时,打包所有各种cloudformation文件时遇到错误。

serverless.yml

resources:
  Resources: ${file(cloudformation/index.js):get-${self:custom.region}}

index.js

var mergeYaml = require('merge-yaml');

module.exports["get-ap-southeast-2"] = async() => {
    // module.exports["get-ap-southeast-2"] => {
    console.log("Using CF script for ap-southeast-2");
    return mergeYaml([
        "./cloudformation/acm.yml",
        "./cloudformation/iam.yml",
        // "./cloudformation/cognito.yml",
        "./cloudformation/iot.yml",
        // "./cloudformation/dynamodb.yml",
        "./cloudformation/dns.yml"
        // "./cloudformation/s3.yml"
    ]);
}

异步错误

SyntaxError:意外令牌( /home/ec2-user/marlin-service/base/cloudformation/index.js:3 module.exports [“ get-ap-southeast-2”] = async()=> {

node --version = 6.10.3 process.version = v6.10.3

我要演示的项目的根目录中有一个webpack.config.js

const StatsWriterPlugin = require("webpack-stats-plugin").StatsWriterPlugin;
const webpack = require('webpack');
const BabiliPlugin = require('babili-webpack-plugin');

module.exports = {
    target: 'node',
    externals: [/aws-sdk/],
    plugins: [
        new StatsWriterPlugin(),
        new BabiliPlugin(),
    ],
    output: {
        // path: path.resolve('dist/assets'),
        publicPath: ''
    },
    module: {
        rules: [{
            test: /src\/.*\.js$/,
            exclude: [
                /node_modules/,
                /test/
            ],
            loader: 'babel-loader',
            options: {
                presets: [
                    [
                        'env',
                        {
                            target: { node: 6.10 }, // Node version on AWS Lambda
                            useBuiltIns: true,
                            modules: false,
                            loose: true,
                        },
                    ],
                    'es2015',
                    'stage-0',
                ],
                plugins: ['transform-runtime']
            },
        }, ],
    }
};

0 个答案:

没有答案