feat: enhance Lambda function configuration and add outputs
- Add parameters for source bucket, repo URL, and branch - Increase timeout to 300s and memory to 512MB - Add ARM64 architecture support - Add S3 GetObject and ListBucket permissions - Use ImportValue for ECR repository ARN - Add resource names for better identification - Export API endpoint, Lambda ARN, and function name
This commit is contained in:
parent
639044388f
commit
5e9c27cbf7
1 changed files with 52 additions and 8 deletions
|
|
@ -1,10 +1,26 @@
|
||||||
AWSTemplateFormatVersion: '2010-09-09'
|
AWSTemplateFormatVersion: '2010-09-09'
|
||||||
Transform: AWS::Serverless-2016-10-31
|
Transform: AWS::Serverless-2016-10-31
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
StageName:
|
StageName:
|
||||||
Type: String
|
Type: String
|
||||||
Default: Prod
|
Default: Prod
|
||||||
Description: Name of the API stage.
|
Description: Name of the API stage
|
||||||
|
|
||||||
|
SourceBucketName:
|
||||||
|
Type: String
|
||||||
|
Default: naputo-blog-source
|
||||||
|
Description: S3 bucket for blog source files
|
||||||
|
|
||||||
|
RepoURL:
|
||||||
|
Type: String
|
||||||
|
Default: "https://git.n-daisuke897.com/nakada0907/n-daisuke897-blog.git"
|
||||||
|
Description: Git repository URL
|
||||||
|
|
||||||
|
RepoBranch:
|
||||||
|
Type: String
|
||||||
|
Default: main
|
||||||
|
Description: Git repository branch
|
||||||
|
|
||||||
Resources:
|
Resources:
|
||||||
|
|
||||||
|
|
@ -27,7 +43,11 @@ Resources:
|
||||||
- Effect: Allow
|
- Effect: Allow
|
||||||
Action:
|
Action:
|
||||||
- s3:PutObject
|
- s3:PutObject
|
||||||
Resource: arn:aws:s3:::naputo-blog-source/*
|
- s3:GetObject
|
||||||
|
- s3:ListBucket
|
||||||
|
Resource:
|
||||||
|
- !Sub "arn:aws:s3:::${SourceBucketName}"
|
||||||
|
- !Sub "arn:aws:s3:::${SourceBucketName}/*"
|
||||||
- PolicyName: LambdaEcrImagePullPolicy
|
- PolicyName: LambdaEcrImagePullPolicy
|
||||||
PolicyDocument:
|
PolicyDocument:
|
||||||
Version: '2012-10-17'
|
Version: '2012-10-17'
|
||||||
|
|
@ -41,26 +61,30 @@ Resources:
|
||||||
- ecr:BatchGetImage
|
- ecr:BatchGetImage
|
||||||
- ecr:BatchCheckLayerAvailability
|
- ecr:BatchCheckLayerAvailability
|
||||||
- ecr:GetDownloadUrlForLayer
|
- ecr:GetDownloadUrlForLayer
|
||||||
Resource: !Sub "arn:aws:ecr:${AWS::Region}:${AWS::AccountId}:repository/*"
|
Resource:
|
||||||
|
Fn::ImportValue: BlogDeployment-RepositoryArn
|
||||||
ManagedPolicyArns:
|
ManagedPolicyArns:
|
||||||
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
|
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
|
||||||
|
|
||||||
MyLambdaFunction:
|
MyLambdaFunction:
|
||||||
Type: AWS::Serverless::Function
|
Type: AWS::Serverless::Function
|
||||||
Properties:
|
Properties:
|
||||||
|
FunctionName: blog-deployment-webhook-handler
|
||||||
PackageType: Image
|
PackageType: Image
|
||||||
ImageUri:
|
ImageUri:
|
||||||
!Join
|
!Join
|
||||||
- ":"
|
- ":"
|
||||||
- - !ImportValue BlogDeployment-RepositoryUri
|
- - !ImportValue BlogDeployment-RepositoryUri
|
||||||
- "latest"
|
- "latest"
|
||||||
Timeout: 30
|
Timeout: 300
|
||||||
MemorySize: 256
|
MemorySize: 512
|
||||||
|
Architectures:
|
||||||
|
- arm64
|
||||||
Environment:
|
Environment:
|
||||||
Variables:
|
Variables:
|
||||||
REPO_URL: "https://git.n-daisuke897.com/nakada0907/n-daisuke897-blog.git"
|
REPO_URL: !Ref RepoURL
|
||||||
REPO_BRANCH: "main"
|
REPO_BRANCH: !Ref RepoBranch
|
||||||
S3_BUCKET: "naputo-blog-source"
|
S3_BUCKET: !Ref SourceBucketName
|
||||||
S3_KEY: "source.zip"
|
S3_KEY: "source.zip"
|
||||||
WEBHOOK_SECRET:
|
WEBHOOK_SECRET:
|
||||||
Fn::Sub:
|
Fn::Sub:
|
||||||
|
|
@ -79,6 +103,7 @@ Resources:
|
||||||
MyApi:
|
MyApi:
|
||||||
Type: AWS::Serverless::Api
|
Type: AWS::Serverless::Api
|
||||||
Properties:
|
Properties:
|
||||||
|
Name: blog-deployment-webhook-api
|
||||||
StageName: !Ref StageName
|
StageName: !Ref StageName
|
||||||
EndpointConfiguration: REGIONAL
|
EndpointConfiguration: REGIONAL
|
||||||
DefinitionBody:
|
DefinitionBody:
|
||||||
|
|
@ -104,3 +129,22 @@ Resources:
|
||||||
description: "Unauthorized - Signature verification failed"
|
description: "Unauthorized - Signature verification failed"
|
||||||
'500':
|
'500':
|
||||||
description: "Server error - Deployment process failed"
|
description: "Server error - Deployment process failed"
|
||||||
|
|
||||||
|
Outputs:
|
||||||
|
ApiEndpoint:
|
||||||
|
Description: API Gateway endpoint URL for webhook
|
||||||
|
Value: !Sub "https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/forgejo-webhook"
|
||||||
|
Export:
|
||||||
|
Name: !Sub "${AWS::StackName}-ApiEndpoint"
|
||||||
|
|
||||||
|
LambdaFunctionArn:
|
||||||
|
Description: Lambda function ARN
|
||||||
|
Value: !GetAtt MyLambdaFunction.Arn
|
||||||
|
Export:
|
||||||
|
Name: !Sub "${AWS::StackName}-LambdaArn"
|
||||||
|
|
||||||
|
LambdaFunctionName:
|
||||||
|
Description: Lambda function name
|
||||||
|
Value: !Ref MyLambdaFunction
|
||||||
|
Export:
|
||||||
|
Name: !Sub "${AWS::StackName}-LambdaName"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue