-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable preview for create and update #1891
Changes from all commits
f66009c
ea2a53b
20b9d99
b539008
db8ebd3
85b7c41
a4ee708
a05520a
784e3ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/bin/ | ||
/node_modules/ | ||
handler.zip |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: aws-native-stable-outputs-preview | ||
runtime: nodejs | ||
description: An example program to test stable outputs during preview |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const handler = async () => { | ||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
message: "Hello World!", | ||
}), | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as pulumi from '@pulumi/pulumi'; | ||
import * as path from 'path'; | ||
import * as ccapi from "@pulumi/aws-native"; | ||
import * as aws from '@pulumi/aws'; | ||
import { zipDirectory } from './zip'; | ||
|
||
const config = new pulumi.Config(); | ||
const desc = config.get('lambdaDescription') ?? 'test lambda'; | ||
const role = new ccapi.iam.Role('lambda-role', { | ||
assumeRolePolicyDocument: { | ||
Version: "2012-10-17", | ||
Statement: [ | ||
{ | ||
Effect: "Allow", | ||
Principal: { | ||
Service: "lambda.amazonaws.com", | ||
}, | ||
Action: "sts:AssumeRole", | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
|
||
const bucket = new ccapi.s3.Bucket('bucket'); | ||
const object = new aws.s3.BucketObjectv2( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meta: Kind of frustrating that many rather basic use cases require layering aws classic on top of aws native in order to make it usable |
||
'object', | ||
{ | ||
source: zipDirectory(path.join(__dirname, 'app'), 'handler.zip'), | ||
bucket: bucket.bucketName.apply(bucket => bucket!), | ||
key: 'handler.zip', | ||
}, | ||
); | ||
const handler = new ccapi.lambda.Function('my-function', { | ||
code: { | ||
s3Bucket: bucket.bucketName.apply(bucket => bucket!), | ||
s3Key: object.key, | ||
}, | ||
description: desc, | ||
runtime: 'nodejs20.x', | ||
handler: 'index.handler', | ||
role: role.arn, | ||
}); | ||
|
||
new ccapi.lambda.Permission('chall-permission', { | ||
functionName: handler.arn, | ||
action: 'lambda:InvokeFunction', | ||
principal: 's3.amazonaws.com', | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "aws-native-naming-conventions", | ||
"main": "index.ts", | ||
"devDependencies": { | ||
"@types/node": "^16" | ||
}, | ||
"dependencies": { | ||
"@pulumi/aws": "^6.63.0", | ||
"@pulumi/aws-native": "^0.8.0", | ||
"@pulumi/pulumi": "^3.74.0", | ||
"archiver": "^7.0.1" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { createWriteStream, promises as fs } from 'fs'; | ||
import * as path from 'path'; | ||
import * as glob from 'glob'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const archiver = require('archiver'); | ||
|
||
export function zipDirectory(directory: string, outputFile: string): Promise<string> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't we do that by using an |
||
// eslint-disable-next-line no-async-promise-executor | ||
return new Promise(async (resolve, reject) => { | ||
// The below options are needed to support following symlinks when building zip files: | ||
// - nodir: This will prevent symlinks themselves from being copied into the zip. | ||
// - follow: This will follow symlinks and copy the files within. | ||
const globOptions = { | ||
dot: true, | ||
nodir: true, | ||
follow: true, | ||
cwd: directory, | ||
}; | ||
const files = glob.sync('**', globOptions); // The output here is already sorted | ||
|
||
const output = createWriteStream(outputFile); | ||
|
||
const archive = archiver('zip'); | ||
archive.on('warning', reject); | ||
archive.on('error', reject); | ||
|
||
// archive has been finalized and the output file descriptor has closed, resolve promise | ||
// this has to be done before calling `finalize` since the events may fire immediately after. | ||
// see https://www.npmjs.com/package/archiver | ||
output.once('close', () => resolve(outputFile)); | ||
|
||
archive.pipe(output); | ||
|
||
// Append files serially to ensure file order | ||
for (const file of files) { | ||
const fullPath = path.resolve(directory, file); | ||
const [data, stat] = await Promise.all([fs.readFile(fullPath), fs.stat(fullPath)]); | ||
archive.append(data, { | ||
name: file, | ||
date: new Date('1980-01-01T00:00:00.000Z'), // reset dates to get the same hash for the same content | ||
mode: stat.mode, | ||
}); | ||
} | ||
|
||
await archive.finalize(); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't pulumitest auto destroy by default?