ed
02/23/2018, 6:56 PMimport aws from 'aws-sdk'
I got it is undefined and I installed it already. Thanks in advancematic
02/23/2018, 8:16 PMaws-sdk
may not have default expose… 🤞 (very unlikely). You can still, though, try importing a concrete module of aws-sdk
, S3, for example.
import { S3 } from 'aws-sdk'
ed
02/23/2018, 8:17 PMmatic
02/23/2018, 8:36 PMkeys
etc…? afaik each module should support custom configuration. S3 for example, handles it like this:
const s3client = new S3({
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
params: {
Bucket: process.env.S3_BUCKET,
},
})
matic
02/23/2018, 8:39 PMaws-sdk
does expose a global module https://github.com/aws/aws-sdk-jsmatic
02/23/2018, 8:40 PMed
02/23/2018, 8:50 PMmatic
02/23/2018, 8:53 PMed
02/23/2018, 8:56 PMimport { fromEvent, FunctionEvent } from 'graphcool-lib'
import { GraphQLClient } from 'graphql-request'
import AWS from 'aws-sdk'
import { v4 } from 'uuid'
interface EventData {
fileType: string
}
export default async (event: FunctionEvent<EventData>) => {
try {
AWS.config.update({
accessKeyId: __ACCESS_KEY__,
secretAccessKey: __SECRET_KEY__,
region: __REGION__
})
const graphcool = fromEvent(event)
const api = graphcool.api('simple/v1')
const { fileType } = event.data
const s3 = new AWS.S3()
const key = v4()
const params = {
Bucket: `cosporter`,
Key: key,
Expires: 60,
ContentType: fileType && fileType
}
const url = await s3.getSignedUrl('putObject', params)
return { data: {url, key} }
} catch (e) {
return { error: `An unexpected error occured. ${e}` }
}
}
ed
02/23/2018, 8:57 PMAWS
is undefined, even if I do console.log(AWS) i got undefinedmax
02/24/2018, 9:34 AMimport * as aws from 'aws-sdk'
max
02/24/2018, 9:34 AMmax
02/24/2018, 9:34 AMed
02/24/2018, 10:23 AM