# AWS SAM with PostgreSQL [TOC] ###### tags: `chatgpt` --- ## 打造一個以 aws-serverless-springboot2-archetype 建構的 AWS SAM 專案,其 Lambda function 需容器化,本地測試時能使用包含 PostgreSQL 的 docker-compose.yml,請給我 template.yml、Dockerfile、pom.xml、docker-compose.yml 的內容 以下是您所需的樣板檔案內容: `template.yml`: ```yaml AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: HelloWorldFunction: Type: AWS::Serverless::Function Properties: CodeUri: target/aws-serverless-springboot2-archetype-1.0.0.jar Handler: com.example.HelloWorldHandler Runtime: java11 MemorySize: 512 Timeout: 10 Events: HelloWorld: Type: Api Properties: Path: /hello Method: get ``` `Dockerfile`: ```dockerfile FROM public.ecr.aws/lambda/java:11 COPY target/aws-serverless-springboot2-archetype-1.0.0.jar /var/task/ CMD ["com.example.HelloWorldHandler::handleRequest"] ``` `pom.xml`: 請在您的 `pom.xml` 中加入以下插件,以容器化 Lambda function: ```xml <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>build-image</goal> </goals> </execution> </executions> <configuration> <image> <name>example/hello-world</name> </image> </configuration> </plugin> </plugins> </build> ```