Serverless Frameworkのresources
を使えば、CloudFormationを利用してS3などのリソースを作成できます。
で、その書き方はおおよそこんな感じ。
serverless.yml
resources:
Resources:
ExampleLogs:
Type: AWS::S3::Bucket
Properties:
BucketName: example-logs
Outputs:
RdsLogs:
Description: "Example Log Bucket"
Value:
Ref: "ExampleLogs"
Outputs
のRef
の値と、Resources
で設定した名前(今回はExampleLogs
)は同じにしましょう。
成功すれば、Serverless FrameworkのOutputsに出力されます。
ちなみにCloudFormationの記法に従えば以下のようにOutputsの値を使用できます。
serverless.yml
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:GetObject"
- "s3:PutObject"
Resource:
- {
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "ExampleLogs"
}
]
]
}