Reputation: 97
I have an issue with aws nodejs sdk with AWS Lambda. From the official documentation im trying to fetch aws\ssm-parameters with lambda.
Doc: [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-ssm/classes/getparameterscommand.html
And this is my Lambda code
import { SSMClient, GetParametersCommand } from "@aws-sdk/client-ssm"
const config = { region: "eu-central-1"}
exports.handler = async (event, context) => {
const client = new SSMClient({ region: config.region});
const command = new GetParametersCommand({Names: ["/my-app/dev/db-url"]});
const response = await client.send(command);
console.log(response);
};
But when run aws lambda function it through error to me as below:
"errorType": "Runtime.UserCodeSyntaxError",
"errorMessage": "SyntaxError: Cannot use import statement outside a module"
I am really new in JS world. Anybody know why its complaining ?
Regards
Upvotes: 0
Views: 1534
Reputation: 104198
From here use the ES5 syntax:
const { SSMClient, GetParametersCommand } = require("@aws-sdk/client-ssm");
Lambda currently only supports ES5 and for SDK version 3 you will need to install the modules as explained here. Locally you need:
npm install @aws-sdk/client-ssm
For SDK V2 this will do:
const AWS = require('aws-sdk');
const ssm = new AWS.SSM();
const val = await ssm.getParameter(
{Name: '/my-app/dev/db-url'}).promise();
console.out(val);
Upvotes: 1