Skip to content
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

Add localstack #286

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ services:
- SESSION_SECRET=super_secret_session_key_change_me_in_production_please
- CI=
- NODE_ENV=development
- LOCALSTACK_HOSTNAME=localstack
jakekreider marked this conversation as resolved.
Show resolved Hide resolved
- EDGE_PORT=4566

db:
image: postgres:15-bookworm
Expand All @@ -32,6 +34,22 @@ services:
volumes:
- postgres:/var/lib/postgresql/data

localstack:
container_name: "cpf-reporter-localstack-main"
image: localstack/localstack
ports:
- "4566:4566" # LocalStack Gateway
- "4510-4559:4510-4559" # external services port range
environment:
- DEBUG=${DEBUG-}
- DOCKER_HOST=unix:///var/run/docker.sock
- AWS_DEFAULT_REGION=${AWS_REGION:-us-west-2}
- REPORTING_DATA_BUCKET_NAME=bucket
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
- "./entrypoint/init-aws.sh:/etc/localstack/init/ready.d/init-aws.sh"

# After starting with `docker compose -f ./docker-compose.dev.yml up`,
# use the console to run commands in the container:
#
Expand Down
48 changes: 48 additions & 0 deletions scripts/tests3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
GetObjectCommand,
CreateBucketCommand,
HeadObjectCommand,
HeadObjectCommandInput,
PutObjectCommand,
PutObjectCommandInput,
S3Client,
} from '@aws-sdk/client-s3'
Fixed Show fixed Hide fixed
import { getSignedUrl as awsGetSignedUrl } from '@aws-sdk/s3-request-presigner'
import type { Prisma } from '@prisma/client'
import { db, getPrismaClient } from 'api/src/lib/db'
Fixed Show fixed Hide fixed
import AWS from 'api/src/lib/aws'

const REPORTING_DATA_BUCKET_NAME = `${process.env.REPORTING_DATA_BUCKET_NAME}`

export default async () => {
try {
await getPrismaClient()

const s3 = AWS.getS3Client()
const key = "12345"
const baseParams: PutObjectCommandInput = {
Bucket: REPORTING_DATA_BUCKET_NAME,
Key: key,
ContentType: 'application/vnd.ms-excel.sheet.macroenabled.12',
ServerSideEncryption: 'AES256',
}
const url = await awsGetSignedUrl(s3, new PutObjectCommand(baseParams), {
expiresIn: 60,
})
console.log("url", url)

const uploadParams: HeadObjectCommandInput = {
Bucket: REPORTING_DATA_BUCKET_NAME,
Key: key,
}
await s3.send(new CreateBucketCommand({
Bucket: REPORTING_DATA_BUCKET_NAME,
}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you were just wanting to use this script as a demo, maybe this could run first and generate a temp bucket, and then in a finally block issue a DeleteBucketCommand to clean up? That way it would succeed/fail deterministically?

await s3.send(new HeadObjectCommand(uploadParams))


} catch (error) {
console.warn('Failed to test s3.')
console.error(error)
}
}
Loading