错误:找不到模块“aws-sdk”aws lambda

问题描述 投票:0回答:1

enter image description here

使用以下功能代码:


'use strict';
//import { AWS } from "@aws-sdk/client-s3"
var AWS = require('aws-sdk');
//import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3"
var s3 = new AWS.S3({

apiVersion: '2012–09–25'

});

var eltr = new AWS.ElasticTranscoder({

apiVersion: '2012–09–25',

region: 'ap-south-1'

});

exports.handler = function(event, context) {

console.log('Executing Elastic Transcoder');

var bucket = event.Records[0].s3.bucket.name;

var key = event.Records[0].s3.object.key;

var pipelineId = '1****************';

if (bucket !== '*****') {

context.fail('Incorrect Input Bucket');

return;

}

var srcKey = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " "));

//the object may have spaces

var newKey = key.split('.')[0];

var fk= "400K";

var sk= "600K";

var om= "1.5M";

var tm= "2M";

var th= "Thumb"

var params = {

PipelineId: pipelineId,

OutputKeyPrefix: newKey + '/',

Input: {

Key: srcKey,

FrameRate: 'auto',

Resolution: 'auto',

AspectRatio: 'auto',

Interlaced: 'auto',

Container: 'auto'

},

Outputs: [{

Key: fk + '/' +'hls4K-' + newKey + '.ts',

ThumbnailPattern: th +'/'+'thumbs4K-{count}',

PresetId: '***************',//HLS v3 400K/s

SegmentDuration:"5"

},

{

Key: sk + '/' +'hls6K-' + newKey + '.ts',

ThumbnailPattern: th +'/'+'thumbs6K-{count}',

PresetId: '**********', //HLS v3 600K/s

SegmentDuration:"5"

},

{

Key: om + '/' +'hls1.5M-' + newKey + '.ts',

ThumbnailPattern: th +'/'+'thumbs1.5M-{count}',

PresetId: '***************', //HLS v3 1.5M/s

SegmentDuration:"5"

},

,

{

Key: tm + '/' +'hls2M-' + newKey + '.ts',

ThumbnailPattern: th +'/'+'thumbs2M-{count}',

PresetId: '*****************', //HLS v3 2M/s

SegmentDuration:"5"

}

],

Playlists: [{

Format: 'HLSv3',

Name: 'hls-'+ newKey,

OutputKeys: [ fk+ '/' +'hls4K-'+ newKey + '.ts',sk + '/' +'hls6K-' + newKey + '.ts',om + '/'

+'hls1.5M-' + newKey + '.ts',,tm + '/' +'hls2M-' + newKey + '.ts']

}]

};

console.log('Starting Job');

eltr.createJob(params, function(err, data){

if (err){

console.log(err);

} else {

console.log(data);

}

context.succeed('Job well done');

});

};

```

Configuration Template:

```
# This AWS SAM template has been generated from your function's configuration. If
# your function has one or more triggers, note that the AWS resources associated
# with these triggers aren't fully specified in this template and include
# placeholder values. Open this template in AWS Application Composer or your
# favorite IDE and modify it to specify a serverless application with other AWS
# resources.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: An AWS Serverless Application Model template describing your function.
Resources:
  videocomporession:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: .
      Description: ''
      MemorySize: 128
      Timeout: 3
      Handler: index.handler
      Runtime: nodejs20.x
      Architectures:
        - x86_64
      EphemeralStorage:
        Size: 512
      EventInvokeConfig:
        MaximumEventAgeInSeconds: 21600
        MaximumRetryAttempts: 2
      PackageType: Zip
      Policies:
        - Statement:
            - Effect: Allow
              Action:
                - logs:CreateLogGroup
              Resource: arn:aws:logs:us-east-2:158624315941:*
            - Effect: Allow
              Action:
                - logs:CreateLogStream
                - logs:PutLogEvents
              Resource:
                - >-
                  arn:aws:logs:us-east-2:158624315941:log-group:/aws/lambda/videocomporession:*
      SnapStart:
        ApplyOn: None
      Events:
        BucketEvent1:
          Type: S3
          Properties:
            Bucket:
              Ref: Bucket1
            Events:
              - s3:ObjectCreated:*
      RuntimeManagementConfig:
        UpdateRuntimeOn: Auto
  Bucket1:
    Type: AWS::S3::Bucket
    Properties:
      VersioningConfiguration:
        Status: Enabled
      BucketEncryption:
        ServerSideEncryptionConfiguration:
          - ServerSideEncryptionByDefault:
              SSEAlgorithm: AES256
  BucketPolicy1:
    Type: AWS::S3::BucketPolicy
    Properties:
      Bucket: Bucket1
      PolicyDocument:
        Statement:
          - Action: s3:*
            Effect: Deny
            Principal: '*'
            Resource:
              - arn:aws:s3:::Bucket1/*
              - arn:aws:s3:::Bucket1
            Condition:
              Bool:
                aws:SecureTransport: false

```
node.js amazon-s3 lambda
1个回答
0
投票

Node.js 18 及更高版本运行时仅包含适用于 JavaScript v3 的 AWS 开发工具包。早期运行时仅包含适用于 JavaScript v2 的 AWS 开发工具包。

我认为你的选择是:

  1. 迁移到并使用 SDK v3
  2. 使用nodejs16.x运行时配置您的Lambda函数并使用SDK v2
  3. 使用 Lambda 函数部署包部署 SDK v2
  4. 配置包含 AWS SDK v2 的自定义 Lambda 层
© www.soinside.com 2019 - 2024. All rights reserved.