Skip to content

Commit

Permalink
Use node 18
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog committed May 14, 2024
1 parent 65fff92 commit ea161be
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v1
with:
node-version: '16.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
18
2 changes: 1 addition & 1 deletion cdkv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class SesSmtpCredentialsProvider extends Construct {
this.provider = new customResource.Provider(this, 'ses-smtp-credentials-provider', {
onEventHandler: new lambda.Function(this, 'ses-smtp-credentials-event', {
code: lambda.Code.fromAsset(path.join(__dirname, 'provider')),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'main.onEvent',
timeout: cdk.Duration.minutes(5),
initialPolicy: [
Expand Down
36 changes: 27 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"clean": "rm -rf ./lib",
"build": "npm run clean && npm run compile && npm run compile-provider && cp -R ./provider/build/ ./lib/provider/ && cp package.json README.md ./lib",
"clean-provider": "rm -rf provider/build/",
"compile-provider": "npm run clean-provider && npx esbuild --platform=node --target=node16 --minify-syntax --external:aws-sdk --bundle --outdir=./provider/build ./provider/main.ts",
"compile-provider": "npm run clean-provider && npx esbuild --platform=node --target=node18 --minify-syntax --external:@aws-sdk/client-iam --bundle --outdir=./provider/build ./provider/main.ts",
"lint": "eslint '*.ts' --fix",
"lint-check": "eslint '*.ts' --max-warnings 0",
"version": "auto-changelog --hide-credit -p && git add CHANGELOG.md"
Expand Down Expand Up @@ -58,7 +58,7 @@
"@aws-cdk/aws-lambda": "^1.89.0",
"@aws-cdk/core": "^1.89.0",
"@aws-cdk/custom-resources": "^1.89.0",
"@types/node": "^16.11.68",
"@types/node": "^18.19.33",
"@typescript-eslint/eslint-plugin": "4.8.2",
"@typescript-eslint/parser": "4.8.2",
"auto-changelog": "^2.2.1",
Expand Down
24 changes: 9 additions & 15 deletions provider/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CloudFormationCustomResourceResponse,
CloudFormationCustomResourceUpdateEvent,
} from 'aws-lambda';
import * as AWS from 'aws-sdk';
import { IAM } from '@aws-sdk/client-iam';
import * as crypto from 'crypto';
import * as utf8 from 'utf8';

Expand Down Expand Up @@ -41,16 +41,15 @@ export const getSmtpPassword = (key: string, region: string) => {

export const onCreate = async (event: CloudFormationCustomResourceCreateEvent): Promise<CloudFormationCustomResourceResponse> => {
const region = event.ResourceProperties.Region;
const iam = new AWS.IAM();
const iam = new IAM();

const now = new Date();
const userName = `ses-user-${now.toISOString().replace('T', '.').replace('Z', '').replace(/:/g, '-')}`;

const user = await iam
.createUser({
UserName: userName,
})
.promise();
});
if (!user.User) {
throw new Error('No user created');
}
Expand All @@ -66,13 +65,11 @@ export const onCreate = async (event: CloudFormationCustomResourceCreateEvent):
Resource: '*',
},
}),
})
.promise();
});
const accessKey = await iam
.createAccessKey({
UserName: user.User.UserName,
})
.promise();
});
const username = accessKey.AccessKey.AccessKeyId;
const secretKey = accessKey.AccessKey.SecretAccessKey;
const password = getSmtpPassword(secretKey, region);
Expand Down Expand Up @@ -100,25 +97,22 @@ export const onUpdate = async (event: CloudFormationCustomResourceUpdateEvent):
};

export const onDelete = async (event: CloudFormationCustomResourceDeleteEvent): Promise<CloudFormationCustomResourceResponse> => {
const iam = new AWS.IAM();
const iam = new IAM();
const [username, accessKeyId] = event.PhysicalResourceId.split(/\//);
await iam
.deleteAccessKey({
UserName: username,
AccessKeyId: accessKeyId,
})
.promise();
});
await iam
.deleteUserPolicy({
UserName: username,
PolicyName: policyName,
})
.promise();
});
await iam
.deleteUser({
UserName: username,
})
.promise();
});
return {
Status: 'SUCCESS',
RequestId: event.RequestId,
Expand Down

0 comments on commit ea161be

Please sign in to comment.