[英]Cannot find EC2 service using nodejs aws-sdk with browserify
我正在將Node.js與browserify結合使用,並且已這樣設置AWS:
var AWS = require('aws-sdk');
AWS.config.region = 'us-west-2b';
這很好。 當我打印到控制台時,將返回一個對象。
但是,當我這樣做時:
var ec2 = new AWS.EC2();
console.log(ec2);
無法找到EC2。 我得到undefined is not a function
。
EC2似乎不存在。 所有文檔都以這種方式指導我。
試試這個腳本,它對我沒有問題。
// ec2script.js
var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';
AWS.config.update({accessKeyId: 'XXXXXXXXXXXXXXXXXXXX', secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'});
var ec2 = new AWS.EC2();
console.log('EC2');
console.log(ec2);
只需執行
>node ec2script.js
這是我得到的回應。
EC2
{ config:
{ credentials:
{ expired: false,
expireTime: null,
accessKeyId: 'XXXXXXXXXXXXXXXXXXXX',
sessionToken: undefined },
credentialProvider: { providers: [Object] },
region: 'us-east-1',
logger: null,
apiVersions: {},
apiVersion: null,
endpoint: 'ec2.us-east-1.amazonaws.com',
httpOptions: { timeout: 120000 },
maxRetries: undefined,
maxRedirects: 10,
paramValidation: true,
sslEnabled: true,
s3ForcePathStyle: false,
s3BucketEndpoint: false,
computeChecksums: true,
convertResponseTypes: true,
dynamoDbCrc32: true,
systemClockOffset: 0,
signatureVersion: 'v4' },
isGlobalEndpoint: false,
endpoint:
{ protocol: 'https:',
host: 'ec2.us-east-1.amazonaws.com',
port: 443,
hostname: 'ec2.us-east-1.amazonaws.com',
pathname: '/',
path: '/',
href: 'https://ec2.us-east-1.amazonaws.com/' } }
如果這不起作用,請檢查您是否使用了正確的訪問密鑰和秘密密鑰。 如果密鑰正確,但仍存在問題,請檢查以確保正確的密鑰策略。
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.