Skip to content

Commit 500357f

Browse files
committed
sample templates
1 parent 1031538 commit 500357f

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

sample-apps/blank/cleanup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
#!/bin/bash
22
set -eo pipefail
3+
OUTPUT_BUCKET=$(aws cloudformation describe-stack-resource --stack-name blank --logical-resource-id bucket --query 'StackResourceDetail.PhysicalResourceId' --output text)
4+
while true; do
5+
read -p "Delete output bucket ($OUTPUT_BUCKET)?" response
6+
case $response in
7+
[Yy]* ) aws s3 rb --force s3://$OUTPUT_BUCKET; aws cloudformation delete-stack --stack-name blank; break;;
8+
[Nn]* ) aws cloudformation delete-stack --stack-name blank --retain-resources bucket; exit;;
9+
* ) echo "Response must start with y or n.";;
10+
esac
11+
done
12+
echo "Deleted function stack"
313
aws cloudformation delete-stack --stack-name blank
414
if [ -f bucket-name.txt ]; then
515
ARTIFACT_BUCKET=$(cat bucket-name.txt)

sample-apps/blank/deploy.sh.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
22
set -eo pipefail
3+
cd function
4+
npm install --production
5+
cd ../
36
aws cloudformation package --template-file template.yaml --s3-bucket MY_BUCKET --output-template-file out.yml
47
aws cloudformation deploy --template-file out.yml --stack-name blank --capabilities CAPABILITY_NAMED_IAM

sample-apps/blank/template.yaml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,6 @@ Description: An AWS Lambda application that uses AWS X-Ray and Amazon S3.
44
Resources:
55
bucket:
66
Type: AWS::S3::Bucket
7-
role:
8-
Type: AWS::IAM::Role
9-
Properties:
10-
AssumeRolePolicyDocument:
11-
Version: "2012-10-17"
12-
Statement:
13-
-
14-
Effect: Allow
15-
Principal:
16-
Service:
17-
- lambda.amazonaws.com
18-
Action:
19-
- sts:AssumeRole
20-
ManagedPolicyArns:
21-
- arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess
22-
- arn:aws:iam::aws:policy/AmazonS3FullAccess
23-
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
24-
Path: /service-role/
257
function:
268
Type: AWS::Serverless::Function
279
Properties:
@@ -31,7 +13,18 @@ Resources:
3113
Description: Write a file to S3.
3214
MemorySize: 128
3315
Timeout: 10
34-
Role: !GetAtt role.Arn
16+
# Function's execution role
17+
Policies:
18+
- AWSLambdaBasicExecutionRole
19+
- AmazonS3FullAccess
20+
- AWSXrayWriteOnlyAccess
21+
- AWSLambdaVPCAccessExecutionRole
22+
VpcConfig:
23+
SecurityGroupIds:
24+
- Fn::ImportValue: lambda-vpc-private-vpc-sg
25+
SubnetIds:
26+
- Fn::ImportValue: lambda-vpc-private-subnet-a
27+
- Fn::ImportValue: lambda-vpc-private-subnet-b
3528
Environment:
3629
Variables:
3730
bucket: !Ref bucket

templates/vpc-private.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,9 @@ Outputs:
9494
Description: Private Subnet B ID
9595
Value: !Ref privateSubnet2
9696
Export:
97-
Name: !Join ["-", [!Ref "AWS::StackName","subnet-b"]]
97+
Name: !Join ["-", [!Ref "AWS::StackName","subnet-b"]]
98+
privateVPCSecurityGroup:
99+
Description: Default security for Lambda VPC
100+
Value: !GetAtt privateVPC.DefaultSecurityGroup
101+
Export:
102+
Name: !Join ["-", [!Ref "AWS::StackName","vpc-sg"]]

templates/vpc-privatepublic.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Resources:
137137
ServiceName: !Sub com.amazonaws.${AWS::Region}.dynamodb
138138
VpcId: !Ref pubPrivateVPC
139139
Outputs:
140-
privateVPCID:
140+
pubPrivateVPCID:
141141
Description: VPC ID
142142
Value: !Ref pubPrivateVPC
143143
Export:
@@ -157,5 +157,10 @@ Outputs:
157157
Value: !Ref privateSubnet2
158158
Export:
159159
Name: !Join ["-", [!Ref "AWS::StackName","private-subnet-b"]]
160+
privateVPCSecurityGroup:
161+
Description: Default security for Lambda VPC
162+
Value: !GetAtt pubPrivateVPC.DefaultSecurityGroup
163+
Export:
164+
Name: !Join ["-", [!Ref "AWS::StackName","vpc-sg"]]
160165

161166

0 commit comments

Comments
 (0)